ItemGiven

Started by Lukey J, Fri 17/04/2020 10:30:29

Previous topic - Next topic

Lukey J

Morning Guys, I've been using tumbleweed template and i can't seem to 'Give' an item to a charater

I looked in the manual but i keep getting this error

Capture" border="0


Code: ags

 // GIVE TO
  else if (Verbs.UsedAction(eGA_GiveTo)) {
  {
    if (ItemGiven == iOldMilk)
    {
    player.Say("Do you want this Cup?");
    cJordan.Say("No, thank you.");
    }
    else Verbs.Unhandled();
    }
  }

Khris

This was apparently changed at some point, you have to use

Code: ags
  if (Verbs.GetItemGiven() == iOldMilk)


Or, if you need to compare it multiple times:
Code: ags
  // before using ItemGiven for the first time in a function
  InventoryItem* ItemGiven = Verbs.GetItemGiven();

  // this will work now
  if (ItemGiven == iOldMilk)

Crimson Wizard

#2
"Unresolved import" error means that variable ItemGiven is declared in script (as import), but not actually created.

What is this "ItemGiven", did you declare it yourself or it was declared by template? If latter, then it's worth reporting this to template author: https://www.adventuregamestudio.co.uk/forums/index.php?topic=54762.0

Khris

It's declared here: https://github.com/dkrey/ags_tumbleweed/blob/master/verbgui.asc#L112
But can only be accessed using this: https://github.com/dkrey/ags_tumbleweed/blob/master/verbgui.asc#L742

I'm guessing it used to be a global variable until the code was refactored, because what Lukey tried is what it says in the official PDF that comes with the template, but apparently it wasn't also updated accordingly.

Crimson Wizard

#4
Quote from: Khris on Fri 17/04/2020 13:09:53
It's declared here: https://github.com/dkrey/ags_tumbleweed/blob/master/verbgui.asc#L112

That's a member of a struct and hidden in asc, but my point is, in Lukey J's code it's used as a regular variable, and if that compiles this means that maybe this variable is declared again somewhere by mistake.

Khris

If I try to use  ItemGiven  I get a compile time "undefined symbol" error, as expected.

When I try to reproduce the error by adding  import InventoryItem* ItemGiven;  to the global header, I get "Variable 'ItemGiven' is already defined"...

Crimson Wizard

#6
Quote from: Khris on Fri 17/04/2020 13:39:07
When I try to reproduce the error by adding  import InventoryItem* ItemGiven;  to the global header, I get "Variable 'ItemGiven' is already defined"...

Ah, it is declared in GlobalScript.asc! That's the mistake. They forgot to remove this declaration.

Code: ags

// main global script file
import InventoryItem*ItemGiven;        // Item given to a character


SMF spam blocked by CleanTalk