Input String

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Meatballsub
Liquid Metal Slime
Posts: 996
Joined: Mon Oct 15, 2007 6:39 pm
Location: Northwest Georgia
Contact:

Input String

Post by Meatballsub »

I'm trying to figure out a way to allow the player to input something into a string and the string save that information. I don't think I've been successful as of yet.

Is the input string command what I should be working with to make this happen? If so, I must be using it wrong. This is what I got...

Code: Select all

script,alminegate,begin
	suspend player
	show textbox (1191)
	wait for textbox
	clear string (4)
	append number (4,135)
	show textbox (1194)
	wait (15)
	advance text box
	input string (5, 2)
	if (string compare (4,5) == true) then (
		show textbox (1193)
		wait for textbox)
	else (
		show textbox (1)
		wait for textbox)
	clear string (5)
	resume player
end
User avatar
msw188
Metal Slime
Posts: 783
Joined: Tue Oct 16, 2007 1:43 am
Location: Los Angeles, CA

Post by msw188 »

Well, right now string 4 has the ascii rep of the number 135, but you are only allowing the player to input two characters into string 5:

Code: Select all

input string (5,2)
The second argument of input string is the max length allowed to be input by the player. What was this 2 supposed to be accomplishing?
I am Srime
User avatar
Meatballsub
Liquid Metal Slime
Posts: 996
Joined: Mon Oct 15, 2007 6:39 pm
Location: Northwest Georgia
Contact:

Post by Meatballsub »

It's actually 3, sorry. I allowed only two to be entered briefly to test something and forgot to put it back to 3. Even with three it doesn't work for me though.
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

The problem is with stringcompare. It turns out that it return -1 (which is the value freebasic uses for 'true') instead of 1 which is the value of the 'true' constant. Get rid of the "== true". While this is a bug in stringcompare which I'll fix, in general writing "== true" is not a great idea, because it's pointless and there might be more commands with this problem.
User avatar
Pepsi Ranger
Liquid Metal Slime
Posts: 1419
Joined: Thu Nov 22, 2007 6:25 am
Location: South Florida

Post by Pepsi Ranger »

If you're using numbers, you might be better off using "number from string." This command reads numbers the way that "input string" reads words, except that you're storing the number directly into a variable.

Code: Select all

input string (4,3,true,false,195,175)
youranswer := number from string (4,-1)
if (youranswer==myanswer) then(
#eliminate the complicated middleman
)
end
Place Obligatory Signature Here
User avatar
Meatballsub
Liquid Metal Slime
Posts: 996
Joined: Mon Oct 15, 2007 6:39 pm
Location: Northwest Georgia
Contact:

Post by Meatballsub »

That did the trick guys, thanks!
Post Reply