I need some help hommies :-)

I’m trying to make a simple banking swf for a game them I’m starting to build.

WHAT TO USE::::
2 dynamic text boxes - variables set to money & bank
1 input text boxes - variable set to amount
1 button

In the first frame of the game I declare the values that you will start out with.

stop();
money = 500;
bank = 0;
amount = 0;

WHAT I WANT TO DO IS PROBABLY NOT HARD I JUST CAN’T THINK ANYMORE LOL. When you type in an amount into the input put it will subtracted the amount from the MONEY variable and add the amount to BANK, simulating that you’re depositing the cash into your account.

I got the sutraction to work but in the code I’m trying to subtract a variable from a variable and it’s not working… here’s the ACTIONS from the BUTTON

on(press){
if(_root.money >= _root.amount){
_root.money -= _root.amount;
_root.bank += _root.amount;
}
}

_root.bank += _root.amount; <------ This is the line that’s not correct. basically what it’s doing is , let’s say you type is 10 in the amount text box it adds the 10 at the end of the 0 that’s already there so it’s like 0, 010, 01010, 0101010, 010101010 etc etc etc or if you type something else in it’s keeps continuing 01010101050 , 0101010105050, etc etc etc… If anyone could help me , it would be greatly appreciated.

Thanks,
Brent
Studio XI
www.studioxidesign.com

Since “amount” comes from a text box, it’s concidered a string variable. Since you can’t add a string to an int, flash treats them both as strings and you get the effect you listed above. Gimme a sec to check the syntaxes, but I believe you can just use Int() to convert a string into an integer. (_root.bank += Int(_root.amount))

Simple!


on(press) {
	if(_root.money >= _root.amount){
		_root.money = number(_root.money) - number(_root.amount);
		_root.bank = number(_root.bank) + number(_root.amount);
	}
}

[FONT=Courier New][LEFT]
[/LEFT]
[/FONT] Hey man I appreciate the help. I knew it wouldn’t be a hard script to write I just go brain dead after working 10-12 hour days.

Cheers,

Brent
Studio XI
www.studioxidesign.com

Your welcome :thumb2:

I’d like to see your game when it’s done!

-Fenrir

absolutely, It’s not going to be anything super great considering this will be my first game in flash. I am a flash web developer so gaming is a new open door for me. I’ll be sure to keep you posted though

Take Care,
Brent
Studio XI
www.studioxidesign.com