Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    How can i make the player level with input()?

    Beginners
    help input
    5
    10
    891
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • landein207
      landein207 last edited by

      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?

      1 Reply Last reply Reply Quote 1
      • R
        Richard F last edited by

        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.

        1 Reply Last reply Reply Quote 2
        • pobtastic
          pobtastic F last edited by pobtastic

          // 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...

          1 Reply Last reply Reply Quote 3
          • landein207
            landein207 last edited by

            Ty i was with some problems with that thanks again

            1 Reply Last reply Reply Quote 1
            • landein207
              landein207 last edited by

              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

              CasualTie5 1 Reply Last reply Reply Quote 1
              • CasualTie5
                CasualTie5 F @landein207 last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • PickleCatStars
                  PickleCatStars F last edited by

                  You can also use float() to do the same thing, as far as I know...

                  1 Reply Last reply Reply Quote 1
                  • landein207
                    landein207 last edited by

                    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 :)

                    1 Reply Last reply Reply Quote 0
                    • PickleCatStars
                      PickleCatStars F last edited by PickleCatStars

                      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.

                      1 Reply Last reply Reply Quote 1
                      • landein207
                        landein207 last edited by

                        Thx @toxibunny it worked also i just copy paste it i isn't that much to write with repetitive parterns :)

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post