Game Programming and Development Tools

Numerical Input - BM – Mene-Mene

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
I'm working some more on my SW PNR GM Assistance Program or SPGMAP (lol) anyway, I've gotten stuck yet again, I'm working on a program load a character into play. Basically because I haven't got my file system up and running yet, it works through input. You take your Word document, and input the data into the program according to the questions it asks you. My problem is it asks like intergers, like for attack, but my cin/input function is a string function, that accepts intergers as strings, therefore I can't input my "string" into my interger variable.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

MastaLlama

Member

Posts: 671
From: Houston, TX USA
Registered: 08-10-2005
Try this code out:


Graphics 800,600,32,2

myString$ = Input("Enter a number into this string variable: ")
y = Input("Enter a number to add to the previously entered number: ")
x = myString$
Text 0,25,"String converted to number."
x = x + y
Text 0,40,"Addition complete."
Text 0,55,"The answer is: "
Text 120,55,x
WaitKey

End

From what I can tell, this line:
x = myString$
does the same as this:
Int(myString$)
sooo...you could make things faster with this:


Graphics 800,600,32,2

myString$ = Input("Enter a number into this string variable: ")
y = Input("Enter a number to add to the previously entered number: ")
x = Int(myString$) + y
Text 0,40,"Addition complete."
Text 0,55,"The answer is: "
Text 120,55,x
WaitKey

End

If myString$ contains text (ex: "hello there") then when the math happens myString$ is just disregarded. BB will say do the following:

myString$ = "hello"
x = myString$ + 2

the value of x will be 2, as a number.

I hope this didn't confuse you

MastaLlama

Member

Posts: 671
From: Houston, TX USA
Registered: 08-10-2005
Ok, after posting I reread your question. Here's a more tailored answer


strAttackPower$ = Input("What is your attack power? ") ; user input is string
numAttackPower = Int(strAttackPower$) ; convert string to integer
Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
You guys never cease to amaze me, it worked.

(BTW, comments are ' in BM, they're ; in BB.)

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

I reserve the full right to change my views/theories at any time.

MastaLlama

Member

Posts: 671
From: Houston, TX USA
Registered: 08-10-2005
Ahh..thanks for the comment on comments. In Visual Basic Script it's ' so the first time in BB I was confused until I understood what the tutorials were doing with the ;...good times.