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.
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
int counter=0
if (counter == 0)
{
// do 1st thing
counter++;
}
else if (counter == 1)
{
// do 2nd thing
counter++;
}
else if (...)
{
// keep adding as many events you need
}
else if (...)
{
// last event here
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.
}
Thanks.
But I'm still getting this wrong.
function hTV_UseInv()
{
int Remote;
Remote =0;
if (Remote == 0){
cLarry.ActiveInventory = iRemote;
oTVscreen.SetView(VPIMP);
oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
Display("You click the power switch on the remote control");
Display("'Oh John.' 'Oh Marcha'['Oh John.' 'Oh Marcha'['Oh John.' 'Oh Marcha' ['Oh John.' 'Oh Marcha'");
Display("Another boring soap opera");
Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
oTVscreen.SetView(VPIMP);
oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
Remote++;
}
else if (cLarry.ActiveInventory == iRemote){
if (Remote == 1){
Display("You click the channel selector on the remote control.");
Display("..I'm Al Fartles, and this is my partner, Fed Ames. We just want to tell you how much we appreciate your support...");
Display("Another boring commercial");
Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
Remote++;
}
else if (cLarry.ActiveInventory == iRemote){
if (Remote == 2){
Display("You click the channel selector on the remote control.");
Display("...and now, ALoHa Producktions is proud to present 'The Revenger of the Software Developers' in full color and sterio sound...");
Display("Another boring musical comedy");
Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
}
}
}
What is wrong with this code? I only get the first messages to appear but not the others.
- 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
if Remote==0 {
}
elsif (Remote==1) && (cLarry.ActiveInventory==iRemote) {
}
elsif (Remote==2) && (cLarry.ActiveInventory==iRemote) {
}
Or put your int on the top of the script, if you don't need it to be global.
Also you want it as:
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.
{
if (Remote == 0)
{
// code
}
else if (Remote == 1)
{
// code
}
else if (Remote == 2)
{
// code
}
else // last line for the remote, if you wish it to reset and start again from 0.
{
// code
}
}
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.
I like to give a line for the opening {, and then ident the block, as it helps me visualise.
int remote = 0; // "int remote;" would work, too; ints are init'd to 0.
function hTV_UseInv()
{
if (player.ActiveInventory == iRemote)
{
if (remote == 0)
{
oTVscreen.SetView(VPIMP);
oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
Display("You click the power switch on the remote control");
Display("'Oh John.' 'Oh Marcha'['Oh John.' 'Oh Marcha'['Oh John.' 'Oh Marcha' ['Oh John.' 'Oh Marcha'");
Display("Another boring soap opera");
Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
oTVscreen.SetView(VPIMP);
oTVscreen.Animate(4, 10, eRepeat, eNoBlock, eForwards);
}
else if (remote == 1)
{
Display("You click the channel selector on the remote control.");
Display("..I'm Al Fartles, and this is my partner, Fed Ames. We just want to tell you how much we appreciate your support...");
Display("Another boring commercial");
Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
}
else if (remote == 2)
{
Display("You click the channel selector on the remote control.");
Display("...and now, ALoHa Producktions is proud to present 'The Revenger of the Software Developers' in full color and sterio sound...");
Display("Another boring musical comedy");
Display("The pimp seems vaguely interested, but not enough to leave his post by the stairs.");
}
else
{
Display("You click the channel selector on the remote control.");
Display("Some message for further interactions.");
}
remote++;
}
// player used something else on the TV
else
{
Display("That doesn't work.");
// alternatively: standard unhandled behavior:
// will only work if you add "import function unhandled_event(int what, int type);" to global header
// unhandled_event(1, 3);
}
}
Omg that worked now perfectly. Thank you so much for this.