Spin Box code crashes game

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Spin Box code crashes game

Post by Ichiro »

So I'm coding a spin box to use in a sound test script, and whenever I test the script, I get a visit from Dr. Watson32 ("GAME.EXE has encountered a problem and needs to close.")

Here's the script:

Code: Select all

script,spin box,begin
	suspend player
	variable(holder, sl, choice)
	holder := create rect(50,40,0)
	set horiz align(holder, edge:center)
	set vert align(holder, edge:center)
	set horiz anchor(holder, edge:center)
	set vert anchor(holder, edge:center)
	sl := create text
	set horiz align(sl, edge:center)
	set vert align(sl, edge:center)
	set horiz anchor(sl, edge:center)
	set vert anchor(sl, edge:center)
	while(not(keyispressed(key:Esc))) do(
		if&#40;choice << 10&#41; then &#40;$31 &#58;= "00"&#41; else &#40;if&#40;choice << 100&#41; then &#40;$31&#58;="0"&#41;&#41;
		append number&#40;31, choice&#41;
		set slice text&#40;sl,31&#41;
	&#41;
	free slice&#40;holder&#41;
	resume player
end
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

That while loop looks infinite to me. If there is no wait of any kind in the while loop, it never gets a chance to poll the keyboard, so it never gets a chance to read any new ESC keypresses.

Although I would expect that to cause game.exe to stop responding, not to crash.

Also, "append number" adds the number to the end of the string, so you should clear the string first. Actually, maybe it is crashing because the infinite loop makes the string incredibly long very fast, and it overflows some memory or something?
Last edited by Bob the Hamster on Fri Jan 14, 2011 6:51 pm, edited 1 time in total.
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

You're going to want to use variable commands instead of string commands I think.
a command of:

choice:= choice+31

instead of

append number(31, choice)

would do what I think you were trying to do.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

31 is the string ID number
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

d'oh, yea I misread that. nvm
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

So an addition of a wait is needed? Sounds easy enough. Now to figure out how to change the value...
Post Reply