Game.DoOnceOnly() question:

Started by geork, Sat 29/09/2012 15:19:30

Previous topic - Next topic

geork

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

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
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!

JSH

#1
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

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


Should be

Code: AGS

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

geork

Haha! I can't believe I did that! :D
Thankyou very much Krus, that should do it :)

SMF spam blocked by CleanTalk