LW Bass 2.0 Use Inventory Problem

Started by Kaspharm, Sat 14/11/2015 15:10:00

Previous topic - Next topic

Kaspharm

Hello, I have a problem with using inventory items in LW Bass 2.0 template
for example:

Code: ags

if(cMe.ActiveInventory == iFlowers) {  
  player.Walk(112, 568, eBlock, eWalkableAreas);
  cMe.Say("Would you like to buy some flowers?");
  cPubowner.Say("Yes, Here`s your money");
  cMe.AddInventory(iMoney);
  cMe.LoseInventory(iFlowers); 
}


works fine, but if I use any other item from inventory on "cPubowner" (not iflowers) nothing happens, game don`t keep unheld events for those items, player dont say "I don't think I should give that away" (like before - without script for iflowers)

what is more interesting if I move "{" before "if" in a script , using any other item from inventory gives me the same effect like using flowers, except for walking. Player just say stuff, i loose flowers (even if i give him something entirely diffrent) i get money, no walking at all...weird. Ccould somoene explain me a problem and show how script should look like?

Snarky

Could you maybe show us an example of a script that isn't working as intended?

Kumpel

Hi,

the unhalndled event works only, as long as you don't set a character_UseInv -function in the global script. Just put an "else player.Say("I don't think I should give that away");" after the if-bracket to get the same effect as "unhandled".

And your other "exploration" is the normal way of AGS handling code. Moving the bracket after if, changes how much code has to be handled in that if-prompt. The engine now only handles the first line (walk) as the result of an if-statement and the rest of the lines are handled always on Character_UseInv.

Khris

#3
Your first problem is easily solved:
Code: ags
  if (...) {
    ...
  }
  else unhandled_event(3, 3);  // item on character


AGS can't tell that you only handle one item; to AGS all that matters is that you have linked a function to cPubowner's "use inventory on" event.
But you can of course always call the global function yourself.

(If you don't want to state the two numbers each time, you could write your own global unhandled() function that checks the current mouse mode and GetLocationType(), uses that to determine the two proper parameters and in turn calls unhandled_event(). For this to work, your unhandled() has to be added below the unhandled_event() declaration.)

As for the second, "more interesting" issue: moving the bracket will screw with your code's logic. { and } are used to group multiple statements together. They allow you to run multiple commands depending on the outcome of an if test, not just one.

If you move the bracket, like this:
Code: ags
  { if (condition)
      command1();
    command2();
    command3();
  }

you might just as well remove them altogether, because here they do absolutely nothing. Compared to the previous code though, only command1() is now depending on the if (in your case: walking to the coordinates), while the rest of them will now always run. Which is what caused the "weird" behavior you saw.

Kaspharm

Thanks for detailed explanation :) Now I understand how it works :)

SMF spam blocked by CleanTalk