Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: geork on Sat 29/09/2012 15:19:30

Title: Game.DoOnceOnly() question:
Post by: geork on Sat 29/09/2012 15:19:30
Hey all!
I've been recently been playing around with with different dialog methods, and I have a question concerning a particular piece of code which I would like to use for efficiencies sake. Basically, each conversation stores it's options, and if any new ones need to be added the next time the conversation is opened the code should do that without losing the old ones. I've tried to do it this way:
//in room
Code (AGS) Select

function hBody_Talk()
{
CurrentDialog = 0;
if(player.HasInventory(iPoster)) CreateNewOption(5, 24);
if(player.HasInventory(iGun)) CreateNewOption(6, 29);
StartDialog(0);
}

and global script
Code (AGS) Select
function CreateNewOption(int index, int sprite){//Add a new index
  if(Game.DoOnceOnly(String.Format("&d,&d,&d", CurrentDialog, index, sprite))){
    //do all the adding dialog stuff
  }
}

Unfortunatly, the code only executes once, despite the string value in Game.DoOnceOnly being different. Have I misunderstood the nature of that function? I searched the forums prior and I found an earlier example using this sort of logic...
Thanks!
Title: Re: Game.DoOnceOnly() question:
Post by: JSH on Sat 29/09/2012 20:45:10
You didn't misunderstand, you just got the formatting character wrong :)

As is the string will always be the same, literally "&d,&d,&d", ignoring the values of the integers and therefore the contents of the if statement only executes once.

Code (AGS) Select

String.Format("&d,&d,&d", CurrentDialog, index, sprite))


Should be

Code (AGS) Select

String.Format("%d,%d,%d", CurrentDialog, index, sprite))
Title: Re: Game.DoOnceOnly() question:
Post by: geork on Sun 30/09/2012 11:30:59
Haha! I can't believe I did that! :D
Thankyou very much Krus, that should do it :)