Hello, new person here, I want to check if my custom resource is here or not.

Basically, in a script attached to the player I have this:
@export var WeaponResource : Item ("Item" being the name of the class in my resource script)

I want to check if I attached something to WeaponResource
so basically I want to do something like this:
if WeaponResource == null:
script
if WeaponResource != null:
other script

But I can't, why ?

Also, sorry if my words are confusing or don't make sense, because, well, I'm confused myself.

  • xyz replied to this.
  • Redstoniste So there are errors after all 🙂
    When you declare a variable (using var) it will only "live" inside code block it was declared in, i.e. the variables are local to the code block they were declared in. This is called variable scope. Note how the error message warns you about the scope. So you need to declare those variables at the scope you intent to use them in. Otherwise they'll "vanish" once the execution leaves the scope they were declared in.

    xyz

    I don't get any errors but it just doesn't work, almost like I wrote nothing

    for exemple, if I write:
    if WeaponResource != null:
    var ItemDamage = WeaponResource.ItemDamage
    var ItemSpeed = WeaponResource.ItemSpeed
    var ItemMaxDamage = WeaponResource.ItemMaxDamage
    if WeaponResource == null:
    var ItemDamage = 5
    var ItemSpeed = 1
    var ItemMaxDamage = 5
    print(ItemDamage)
    print(ItemSpeed)
    print(ItemMaxDamage)

    It gives me an error saying that I didn't define ItemDamage

    • xyz replied to this.

      Redstoniste So there are errors after all 🙂
      When you declare a variable (using var) it will only "live" inside code block it was declared in, i.e. the variables are local to the code block they were declared in. This is called variable scope. Note how the error message warns you about the scope. So you need to declare those variables at the scope you intent to use them in. Otherwise they'll "vanish" once the execution leaves the scope they were declared in.