Give a Character more than one Item (not the MC)

Started by HeyLuigi, Fri 11/10/2013 17:59:34

Previous topic - Next topic

HeyLuigi

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

if (cEgo.ActiveInventory==iXY) [

}
}

but it only works with one item.
thank you :)

Khris

Try this:

Code: ags
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.)

HeyLuigi

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?


Khris

If there's an error in my code, please point it out, so I can fix it.

monkey0506

It looks to me like he swapped the asterisk with an apostrophe.

HeyLuigi

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

Khris

"if (1)" is evaluated as "if (true)", same for 2 and 3.

You need
Code: ags
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.

HeyLuigi

thank you for your answer
i've tried this but ags say "undefined token 'items'"

Mandle

#9
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...

HeyLuigi

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...

Khris

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.

HeyLuigi

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.


Khris

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?

HeyLuigi

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. :(

Khris

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.

SMF spam blocked by CleanTalk