migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.06k stars 64 forks source link

Cannot find type 'Area2D' in scope #442

Closed roydbt closed 4 months ago

roydbt commented 5 months ago

I am trying to follow the "Your First Extension" tutorial (with some adjustments) and getting an error in the second section. Here is my "Package.swift" file:

// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "First2DGameSwift",
    platforms: [.macOS(.v13)],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "First2DGameSwift",
            type: .dynamic,
            targets: ["First2DGameSwift"]),
    ],
    dependencies: [
        .package(url: "https://github.com/migueldeicaza/SwiftGodot", branch: "main"),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "First2DGameSwift",
            dependencies: [
                "SwiftGodot",
            ],
            swiftSettings: [.unsafeFlags(["-suppress-warnings"])]),
        .testTarget(
            name: "First2DGameSwiftTests",
            dependencies: ["First2DGameSwift"]),
    ])

and here is my "Sources/First2DGameSwift/Player.swift" file:

import Foundation
import SwiftGodot

@Godot
class Player: Area2D {}

Inside "Player.swift", on the last line, I am getting a "Cannot find type 'Area2D' in scope" error. Changing Area2D to "CharacterBody2D" as the tutorial suggests doesn't fix the error.

Versions:

ridigilis commented 5 months ago

Did you complete step 6 of the first section? I'm guessing the file would be called "First2DGameSwift.swift", and since its omitted here alongside the other files you've provided, I'm wondering if that step may have been skipped by mistake?

roydbt commented 5 months ago

Here is "First2DGameSwift.swift":

// The Swift Programming Language
// https://docs.swift.org/swift-book

import SwiftGodot

#initSwiftExtension(cdecl: "swift_entry_point", types: [])

Also it might be worth mentioning that the error is in the Xcode editor and not in the build process.

ridigilis commented 5 months ago

In Package.swift, in your SwiftGodot dependency, try changing the branch from "main" to "db759c5776933a12f937e2449830d01e6ceae5ea".

I revisited my own tutorial run-through, and when I updated the packages I got the same inline errors. That commit was what the project was on when I completed it. A recent commit may have introduced the issue.

This should unblock you for the time being!

roydbt commented 5 months ago

That didn't fix the issue, but after restarting Xcode, waiting for it to index the files about 3 times, build twice, and build the documentation, it worked even on the main branch!