Depositing money by TextBox (SOLVED)

Started by R4L, Wed 30/11/2005 14:50:01

Previous topic - Next topic

R4L

Ok, I have a GUI and I have a text box where you can enter money amounts(money is game.score) to store in the bank after clicking on a checkmark button. I had this in my script for the GUI called DEPOSIT:

if (interface==DEPOSIT){
if (button==2){
GetTextBoxText(DEPOSIT,1,"deposit");
GiveScore(-deposit);
}
}
Button 2 refers to the checkmark box, which means OK.
It didn't work but I thought it would. Is there something I am missing or am I completely wrong? Thanks.

Ashen

1.
The last parameter of GetTextBoxText is a string - make sure you've declared string deposit; somewhere, and take away the inverted commas (") around it.

2.
Since it's a string, you can't use it in GiveScore() commands. Add a StringtoInt(deposit) command in there, something like:

Code: ags

if (button==2){
string deposit; // If you haven't declared it already - ignore if you have
GetTextBoxText(DEPOSIT,1,deposit);
int dep = StringToInt (deposit);
GiveScore(-dep);
}
I know what you're thinking ... Don't think that.

R4L

#2
Oh yeah, I forget about these functions! :D Thanks Ashen.

EDIT: Can I add code to let the player only enter numbers into the text box and limit the amount of numbers?

Ashen

It's a little rough (letters/extra numbers appear for a second, then vanish) but something like this should work:

Create another string, called temp, then paste this into repeatedly_execute:

Code: ags

if (IsGUIOn (DEPOSIT)) {
    GetTextBoxText(DEPOSIT, 2, temp);
    int length = StrLen(temp);
    if (length > 0 && length < 4) { // Replace 4 with the maximum numbers you want
      int chara = StrGetCharAt(temp, length-1);
      if (chara < 48 || chara > 57) {
        StrSetCharAt(temp, length-1, 0);
      }
    }
    else if (length > 4) StrSetCharAt(temp, 4, 0);
    SetTextBoxText(DEPOSIT, 2, temp);
}


(You might have to put it in rep_ex_always, if DEPOSIT is popup-modal.)

Beyond that, maybe you could add a keypad to the GUI and use a label, rather than a textbox and the actual keyboard. That'd probably make it easier to limit the input.
I know what you're thinking ... Don't think that.

R4L

#4
Thanks Ashen. One question though. If the GUI is off but is Normal is that okay?

EDIT: I think it might work, I just have to get home to try it!

SMF spam blocked by CleanTalk