Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: LupaShiva on Sun 29/08/2010 19:28:48

Title: Label message second time object [SOLVED]
Post by: LupaShiva on Sun 29/08/2010 19:28:48
Ok i wanted to create a script that show a message in a label when i take an object and dissapears after few seconds but when i click again in the object i wanted to do another script because already got the object, but it always show the label saying "new item taken".


function hSacoLixo_Interact()
{
 if (cJake.HasInventory(iPills)){
 cJake.Say("There's nothing more there.");
 GiveScore(-5);
 GUITexto.Text = ("");}
 else
 cJake.Say ("I found some Sleeping pills.");
 GUITexto.Text = ("New item taken.");
 cJake.AddInventory (iPills);
 GiveScore(5);
 SetTimer(1, (5*40));
 
}


Thank you for the help
Title: Re: Label message second time object
Post by: Chrille on Sun 29/08/2010 19:46:35
I think you're missing some brackets. Your current code does nothing for the 'else' condition and runs the code below it every time. Here's how the code should look:


function hSacoLixo_Interact()
{
 if (cJake.HasInventory(iPills)){
 cJake.Say("There's nothing more there.");
 GiveScore(-5);
 GUITexto.Text = ("");
 }
 else {
 cJake.Say ("I found some Sleeping pills.");
 GUITexto.Text = ("New item taken.");
 cJake.AddInventory (iPills);
 GiveScore(5);
 SetTimer(1, (5*40));
 }
}
Title: Re: Label message second time object
Post by: LupaShiva on Sun 29/08/2010 19:50:29
Yeah it works but now it keep taking 5 from my score  :(
Title: Re: Label message second time object
Post by: GarageGothic on Sun 29/08/2010 20:22:41
Because you subtract five points from the score with the "GiveScore(-5);" call. Unless you want to punish the player for clicking the hotspotagain after picking up the pills that line shouldn't be there at all.

Also, the way its scripted now, the player will be able to go back and pick up more pills once he uses/loses them. I don't know if that's intentional.
Title: Re: Label message second time object
Post by: Dualnames on Mon 30/08/2010 16:45:31

function hSacoLixo_Interact()
{
 if (cJake.HasInventory(iPills)){
 cJake.Say("There's nothing more there.");
if (Game.DoOnceOnly("pillscore")) { 
    GiveScore(-5);
  }
 GUITexto.Text = ("");
 }
 else {
 cJake.Say ("I found some Sleeping pills.");
 GUITexto.Text = ("New item taken.");
 cJake.AddInventory (iPills);
 GiveScore(5);
 SetTimer(1, (5*40));
 }
}


That should do it.
Title: Re: Label message second time object
Post by: LupaShiva on Mon 30/08/2010 17:15:13
It worked  ;) thank you a lot  :D