Author Topic: I need code for "Using same Item again on same hotspot or object". Solved!  (Read 477 times)  Share 

Hi all and Happy new year!

Does anybody know the code on this one?

What code do I use when I use a same item on same hotspot or object to get different messages?
I don't want a random messages to show up. I want the game to display another messages after I click on it again.

In case if you don't understand me.
Remember in Leisure suit Larry 1 EGA/VGA when you where in the toilet.  There was a messages on the walls there. And when you click on the wall you could read a different messages after each time you clicked on it.

And also when you clicked on the TV with the remote. You got a another messages after the last messages.





 
« Last Edit: 10 Jan 2017, 23:53 by Fribbi »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
There are different ways to do the same.

If you only want 2 things, you can use a if Game.DoOnceOnly for the first time, and then just else...

If you want more than 2 events, you can add an int variable

Code: Adventure Game Studio
  1. int counter=0
  2.  
  3. if (counter == 0)
  4. {
  5.     // do 1st thing
  6.     counter++;
  7. }
  8. else if (counter == 1)
  9. {
  10.     // do 2nd thing
  11.     counter++;
  12. }
  13. else if (...)
  14. {
  15.     // keep adding as many events you need
  16. }
  17. else if (...)
  18. {
  19.     // last event here
  20.     counter=0; // if you want it to repeat (in this case you can just use a else instead of else if), or counter++; is you want it to stop.
  21. }
  22.  
There are those who believe that life here began out there...

Thanks.

But I'm still getting this wrong.

Code: Adventure Game Studio
  1. function hTV_UseInv()
  2. {
  3.  
  4. int Remote;
  5. Remote =0;
  6. if (Remote == 0){
  7. cLarry.ActiveInventory = iRemote;
  8. oTVscreen.SetView(VPIMP);
  9. oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
  10. Display("You click the power switch on the remote control");
  11. Display("'Oh John.'  'Oh Marcha'['Oh John.'  'Oh Marcha'['Oh John.'  'Oh Marcha' ['Oh John.'  'Oh Marcha'");
  12. Display("Another boring soap opera");
  13. Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
  14. oTVscreen.SetView(VPIMP);
  15. oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
  16. Remote++;
  17. }
  18. else if (cLarry.ActiveInventory == iRemote){
  19. if (Remote == 1){
  20.   Display("You click the channel selector on the remote control.");
  21.   Display("..I'm Al Fartles, and this is my partner, Fed Ames. We just want to tell you how much we appreciate your support...");
  22.   Display("Another boring commercial");
  23.   Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
  24. Remote++;
  25. }
  26. else if (cLarry.ActiveInventory == iRemote){
  27. if (Remote == 2){
  28.  Display("You click the channel selector on the remote control.");
  29.  Display("...and now, ALoHa Producktions is proud to present 'The Revenger of the Software Developers' in full color and sterio sound...");
  30.  Display("Another boring musical comedy");
  31.  Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
  32.    }
  33.  
  34. }
  35. }

What is wrong with this code?  I only get the first messages to appear but not the others.
« Last Edit: 10 Jan 2017, 00:57 by Fribbi »

RickJ

  • fix'n one thing and break'n two ...
    • I can help with scripting
    •  
    • I can help with story design
    •  
  • INDENT YOUR CODE PROPERLY
  • Define Remote outside the bounds of your function.  Variables defined within a function are created when the function is invoked and destroyed when the function returns.  In this case values are not returned from one execution to the next.
  • Remote is being set to a value of zero each time the function is called. Not sure but I think AGS variables are automatically initialized to zero at game start.  If not then initialize Remote in the game_start() event handler.
  • if-else structure is wrong.  You would see it if you indented your code properly
Code: Adventure Game Studio
  1. if Remote==0 {
  2. }
  3. elsif (Remote==1) && (cLarry.ActiveInventory==iRemote) {
  4. }
  5. elsif (Remote==2) && (cLarry.ActiveInventory==iRemote) {
  6. }
  7.  
  8.  

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
Or put your int on the top of the script, if you don't need it to be global.

Also you want it as:

Code: Adventure Game Studio
  1. if (cLarry.ActiveInventory == iRemote) // you want to check first if he's using the remote, otherwise any item the player will use will run the code.
  2. {
  3.     if (Remote == 0)
  4.     {
  5.         // code
  6.     }
  7.     else if (Remote == 1)
  8.     {
  9.         // code
  10.     }
  11.     else if (Remote == 2)
  12.     {
  13.         // code
  14.     }
  15.     else // last line for the remote, if you wish it to reset and start again from 0.
  16.     {
  17.         // code
  18.     }
  19. }
  20. else Display("That doesn't help change the channel."); // or some line to tell the player that that item doesn't do anything to the tv.
  21.  

I like to give a line for the opening {, and then ident the block, as it helps me visualise.
« Last Edit: 10 Jan 2017, 10:09 by Cassiebsg »
There are those who believe that life here began out there...

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
  • Khris worked on a game that was nominated for an AGS Award!
Code: Adventure Game Studio
  1. int remote = 0; // "int remote;" would work, too; ints are init'd to 0.
  2.  
  3. function hTV_UseInv()
  4. {
  5.   if (player.ActiveInventory == iRemote)
  6.   {
  7.     if (remote == 0)
  8.     {
  9.       oTVscreen.SetView(VPIMP);
  10.       oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
  11.       Display("You click the power switch on the remote control");
  12.       Display("'Oh John.'  'Oh Marcha'['Oh John.'  'Oh Marcha'['Oh John.'  'Oh Marcha' ['Oh John.'  'Oh Marcha'");
  13.       Display("Another boring soap opera");
  14.       Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
  15.       oTVscreen.SetView(VPIMP);
  16.       oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
  17.     }
  18.     else if (remote == 1)
  19.     {
  20.       Display("You click the channel selector on the remote control.");
  21.       Display("..I'm Al Fartles, and this is my partner, Fed Ames. We just want to tell you how much we appreciate your support...");
  22.       Display("Another boring commercial");
  23.       Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
  24.     }
  25.     else if (remote == 2)
  26.     {
  27.       Display("You click the channel selector on the remote control.");
  28.       Display("...and now, ALoHa Producktions is proud to present 'The Revenger of the Software Developers' in full color and sterio sound...");
  29.       Display("Another boring musical comedy");
  30.       Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
  31.     }
  32.     else
  33.     {
  34.       Display("You click the channel selector on the remote control.");
  35.       Display("Some message for further interactions.");
  36.     }
  37.     remote++;
  38.   }
  39.   // player used something else on the TV
  40.   else
  41.   {
  42.     Display("That doesn't work.");
  43.     // alternatively: standard unhandled behavior:
  44.     // will only work if you add "import function unhandled_event(int what, int type);" to global header
  45.     // unhandled_event(1, 3);  
  46.   }
  47. }

Omg that worked now perfectly.  Thank you so much for this.