Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Lukey J on Fri 17/04/2020 10:30:29

Title: ItemGiven
Post by: Lukey J on Fri 17/04/2020 10:30:29
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

(https://i.ibb.co/KbRj6CT/Capture.png) (https://imgbb.com/)


Code (ags) Select

// 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();
    }
  }
Title: Re: ItemGiven
Post by: Khris on Fri 17/04/2020 12:29:04
This was apparently changed at some point, you have to use

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

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

  // this will work now
  if (ItemGiven == iOldMilk)
Title: Re: ItemGiven
Post by: Crimson Wizard on Fri 17/04/2020 12:47:20
"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
Title: Re: ItemGiven
Post by: Khris on Fri 17/04/2020 13:09:53
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.
Title: Re: ItemGiven
Post by: Crimson Wizard on Fri 17/04/2020 13:26:00
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.
Title: Re: ItemGiven
Post by: Khris on Fri 17/04/2020 13:39:07
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"...
Title: Re: ItemGiven
Post by: Crimson Wizard on Fri 17/04/2020 13:42:06
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) Select

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