Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HeyLuigi on Fri 11/10/2013 17:59:34

Title: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Fri 11/10/2013 17:59:34
Hey there,

I wanted to finish my game but on the last scene the MC must give a other character some items. I know that there is the
Code (ags) Select

if (cEgo.ActiveInventory==iXY) [

}
}

but it only works with one item.
thank you :)
Title: Re: Give a Character more than one Item (not the MC)
Post by: Khris on Fri 11/10/2013 18:06:31
Try this:

Code (ags) Select
int items;

function cOther_Useinv() {

  // walk to, face character, etc.

  InventoryItem *ai = cEgo.ActiveInventory;
  if (ai == iBrick || ai == iPot || ai == iXY) {
    player.RemoveInventory(ai);
    items++;
    if (items == 3) {
      // stuff happens
    }
  }
  else cOther.Say("I don't want that.");
}


(Note that this will only work properly if the items are unique, since the code only checks how many items were given in total.)
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Fri 11/10/2013 18:29:30
thank you for your fast answer, I've tried that but i became this error.

Parse error in expr near 'ai

could you also help me, please?
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Fri 11/10/2013 19:53:42
Problem solved, thanks!
Title: Re: Give a Character more than one Item (not the MC)
Post by: Khris on Fri 11/10/2013 22:46:08
If there's an error in my code, please point it out, so I can fix it.
Title: Re: Give a Character more than one Item (not the MC)
Post by: monkey0506 on Fri 11/10/2013 23:11:43
It looks to me like he swapped the asterisk with an apostrophe.
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Sat 12/10/2013 14:59:42
I change something and now i don't get any error but if you give the character an item all options happen :/
heres my code, could you help me?
______
function cBaul_UseInv()
{
InventoryItem *ai = cEgo.ActiveInventory;
if(ai == iDigiS|| ai == iGescS|| ai==iGebS){
  player.LoseInventory(ai);
   if (2){
    dDigiS.Start();
    StopDialog();
  }
   if(1){
    dDigiS.Start();
    StopDialog();
  }
   if(3){
    dBaulr.Start();
    StopDialog();
  }

}
}
______
thanks
Title: Re: Give a Character more than one Item (not the MC)
Post by: Khris on Sat 12/10/2013 16:02:35
"if (1)" is evaluated as "if (true)", same for 2 and 3.

You need
Code (ags) Select
function cBaul_UseInv()
{
  InventoryItem *ai = cEgo.ActiveInventory;
  if(ai == iDigiS || ai == iGescS || ai==iGebS) {
    player.LoseInventory(ai);
    items++;
    if (items < 3) dDigiS.Start();
    else dBaulr.Start();
  }
}


No need to call StopDialog() here, that command is obsolete anyway now.
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Sat 12/10/2013 16:33:40
thank you for your answer
i've tried this but ags say "undefined token 'items'"
Title: Re: Give a Character more than one Item (not the MC)
Post by: Mandle on Sat 12/10/2013 16:44:06
Quote from: HeyLuigi on Sat 12/10/2013 16:33:40
thank you for your answer
i've tried this but ags say "undefined token 'items'"

This means that either your:

int items;

is now missing from your code or is in a place that the function that references it cannot respond to.

For example it may be contained inside a different function by mistake, in which case it will only work inside that particular function and not the one you are referring to it from.

Here is why:

The "int items;" in Khris' code above defines a variable called "items" as a basic integer number (no decimal places).

If the variable is not defined then AGS tells you it is an "undefined token" which means any label describing a variable, object name, character name etc which the program has not been correctly told to recognize.

For a simple fix just add the int items; command at the top outside of all functions and then all functions can identify it and respond to it when it is referenced.

Hope this helped...
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Sun 13/10/2013 15:01:31
I do not go on...
sorry, but I still do not quite understand it.
_____
function cBaul_UseInv()
{
  InventoryItem *ai =
cEgo.ActiveInventory;
// iGebS is the right item
if(ai == iDigiS|| ai == iGescS|| ai==iGebS){
  player.LoseInventory(ai);
  int items;
  if (items < 2) dDigiS.Start();
  else dBaulr.Start();
}
}
____
if I give the character the rigt object (iGebs) the dDigiS dialog start...
Title: Re: Give a Character more than one Item (not the MC)
Post by: Khris on Sun 13/10/2013 15:11:39
Could you simply tell us what you want to happen?
I thought you wanted to start dialog dDigiS after the first two items are given, then dBaulr when he gets the third and final one.

As for the placement of "int items;", it has to go ABOVE the function, not inside, like I outlined in my very first reply and Mandle explained. If you put it inside the function, items will constantly get reset to 0, but we need it to count the number of items given in total.
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Sun 13/10/2013 15:22:39
the first two items are the wrong items, when the mc give them to the character the dialog dDigiS should start. But if the mc give the character the item three (iGebS) the dialog dBaulr should start.
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Sun 13/10/2013 15:54:56
solved! thanks
Title: Re: Give a Character more than one Item (not the MC)
Post by: Khris on Sun 13/10/2013 16:39:02
I see, I always assumed the player is supposed to give the NPC more than one item for something to happen.
It the NPC is just supposed to react differently, you won't need the items variable stuff.
Are you sure this is solved?
What I'm asking is, did you consider the possibility that the player gave them some item other than the three?
Title: Re: Give a Character more than one Item (not the MC)
Post by: HeyLuigi on Sun 13/10/2013 18:12:39
it isn't solved... when i tested it i gave the character at first a wrong item then the right item. That worked but when i gave the character at first the right item the dDigiS dialog start. :(
Title: Re: Give a Character more than one Item (not the MC)
Post by: Khris on Sun 13/10/2013 19:34:31
Could you tell us exactly what you want to happen? Without referring to code, focus purely on the game design aspect.
Which items do what?
I guess it's a lot easier that way.