How can i make the player level with input()?
-
ok so im trying to do a input() players levels like this
Lv = input("write your level here",false)
atk = 2 + 2 * Lv
def = 1 + 0.25 * Lv
Hp = 6 + 4 * Lv
Hpmax = 6 + 4 * Lv//the idea is each level add 4 to hp and hp max
//add 2 to atack and add 1 each 4 levels//rest of my program
It won't work because it says
Operation not recognized.
(Details: int, multiply, string)How can i make this work if it is even possible?
-
Input returns a string and I think this is your problem, you need lv to be an integer so you can convert it using the int() function.
Something like:lv = int(lv)
After getting the user input.
-
// Input validation! // A non-numeric input will evaluate to zero, so keep looping until "good" input is detected. while int( Lv ) == 0 loop Lv = input("write your level here",false) repeat // Cast to an integer. Lv = int( Lv )
Note though that
int()
will cast to a whole number, so if you need say 3.6 - that'll end up being just 3... -
Ty i was with some problems with that thanks again
-
Ok so i have been kinda ignoring this problem because it isn't that problematic but i still would like to solve it is when i put words into the box the program will accept it and set the level vaule to 0 so how can i do to it accept the numbers beathen -4 and 20 (already made that thanks to ppl here) and ignore when the player writes words it repeat the loop to ask to input the level number
-
@landein207 if you're talking about string inputs, as soon as you use the int() function, all letters will be erased, so int("3&-€+") = 3
at least that's how I remember it
-
You can also use float() to do the same thing, as far as I know...
-
Ok i think i will put the code here that the letters still getting in
LV = input( "write you love here",false)
While int(LV) <= -5 or int(LV) >= 21 loop
LV = input( "write you love here",false)
Loop
Lv = int(LV)So with the code check how i can modify it to the loop repeat when a letter is input into the LV box i realy apreciate the help :)
-
There’s a strcontains() function. You could do a load of those, one for each letter :) Have a look in the ‘text handling’ section in the help..
If you wanted to get a bit more clever about it, you could make an array with all the different letters in (in speechmarks), and then loop through that. It’d save you loads of typing.
-
Thx @toxibunny it worked also i just copy paste it i isn't that much to write with repetitive parterns :)