Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to cycle through numbers..?  (Read 8321 times)

0 Members and 1 Guest are viewing this topic.

DarrenReeder

    Topic Starter


    Rookie

    How to cycle through numbers..?
    « on: October 26, 2009, 11:18:54 AM »
    I am currently making a small batch file game and im making it so your account (i already made a register system) has money... basicly i plan to make it so you have a Directory in yuor account files called 'Money' then inside there it will have another folder with your money (ie: Money\1000)... ..

    now if i want to add 500 to my 1000 money i want to be able to...Rmdir 1000 and mkdir 1500 and i plan to do this using Variables.... now basicly i want to know if i can cycle through number 0-999999 so i can do :

    Code: [Select]
    number=0-999999
    if exist %number% goto A

    :A

    number2=number+500
    rmdir number
    mkdir number2

    ok, so thats sort of what i wanna do? the 'number' variable i basicly want it like %random% but it goes through all the numbers instead of chooses one... i hope this sorta makes sense and it wuld be great for help on how to make the 'if exist' cycle through loads of numbers :-)

    gpl



      Apprentice
    • Thanked: 27
      Re: How to cycle through numbers..?
      « Reply #1 on: October 26, 2009, 11:42:04 AM »
      I think this is too clunky, why not have a FILE called Money that holds your value ? It is easier to read and write a file of a known name than it is to check if a directory exists.

      Unless you have a really good reason for using a directory, isnt this simpler ?
      Code: [Select]
      :: Read the money value
      Set /P MyMoney=<Money

      :: add 500 to it
      Set /A MyMoney=MyMoney + 500

      :: save the value back
      Echo MyMoney>Money

      DarrenReeder

        Topic Starter


        Rookie

        Re: How to cycle through numbers..?
        « Reply #2 on: October 26, 2009, 11:48:26 AM »
        i use a register system so you log in everytime u load the batch file...so i need it to be a permanent Save...if you know what i mean?

        gpl



          Apprentice
        • Thanked: 27
          Re: How to cycle through numbers..?
          « Reply #3 on: October 26, 2009, 11:55:40 AM »
          The file Money is permanent, across logins - you only load a value as you need to use it -- think config files

          DarrenReeder

            Topic Starter


            Rookie

            Re: How to cycle through numbers..?
            « Reply #4 on: October 26, 2009, 11:58:20 AM »
            im not too sure i understand your thing..could you explain like what its doing please? lol.. im not too confident with this stuff..

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: How to cycle through numbers..?
            « Reply #5 on: October 26, 2009, 03:42:21 PM »
            Gpl you are messing up the op and not even touching on what the op wants. Darren, try looking at FOR /?

            Your code should be (I think):

            for /l %%a in (0,1,99999) do if exist %%a set mon=%%a &goto continue
            :continue
            commands
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            DarrenReeder

              Topic Starter


              Rookie

              Re: How to cycle through numbers..?
              « Reply #6 on: October 26, 2009, 07:19:24 PM »
              so that would mean i could then do

              if exist %%a...



              and %%a would hold all numbers from 0-999999 ?

              billrich

              • Guest
              Re: How to cycle through numbers..?
              « Reply #7 on: October 26, 2009, 08:38:14 PM »

              C:\batextra>type mon.bat
              Code: [Select]
              @echo off

              FOR /L %%i IN (0,1,999999) DO (
              echo %%i
              if %%i==89 set var=%%i && goto eof

              )
              :eof
              echo outside var=%var%

              OUTPUT:

              C:\batextra>mon.bat
              .
              .
              .

              76
              77
              78
              79
              80
              81
              82
              83
              84
              85
              86
              87
              88
              89
              outside var=89

              C:\batextra>echo %var%
              89

              C:\batextra>

              REM:  The For loop variable, %%i,  only contains one number at any one time. At the end of the loop %%i = %var% = 999999

              After the loop works as you need it to,  then add your other commands.
              The numbers inside the for loop will always exist.  The test for money folders will require more than a test of the for loop counter.
              « Last Edit: October 26, 2009, 09:16:52 PM by billrich »

              gh0std0g74



                Apprentice

                Thanked: 37
                Re: How to cycle through numbers..?
                « Reply #8 on: October 26, 2009, 09:52:42 PM »
                I am currently making a small batch file game
                a small question just to satisfy my curiosity. why do you want to use batch for programming a game, when for one thing, it can't even do floating maths properly and moreover, you are dealing with money. My suggestion, if you want to do games or solve other real problems...use a programming language such as Python (or others), but not batch.

                FYI, you can build games easily with pygame.

                BatchFileBasics



                  Hopeful

                  Thanked: 18
                  Re: How to cycle through numbers..?
                  « Reply #9 on: October 26, 2009, 09:57:45 PM »
                  although i agree with you ghost, he probably isn't trying to make a legit programming game, im sure hes just trying to make something he can say "yup, i made it" then stop playing it maybe 1/2 hour tops later and goes off to start a new one.
                  When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                  Salmon Trout

                  • Guest
                  Re: How to cycle through numbers..?
                  « Reply #10 on: October 27, 2009, 02:52:42 AM »
                  Good luck with 999999 files or folders in a directory...

                  DarrenReeder

                    Topic Starter


                    Rookie

                    Re: How to cycle through numbers..?
                    « Reply #11 on: October 27, 2009, 06:18:30 AM »
                    i dont want 99999 folders... i want it so like....

                    the folder is my money... so i got the directory..

                    money\500 (500 is my cash)

                    then i wanna find a way of Getting that 500 into my batch file so i can do

                    500+1000(example)


                    So mabe im trying to do the wrong thing?

                    BC_Programmer


                      Mastermind
                    • Typing is no substitute for thinking.
                    • Thanked: 1140
                      • Yes
                      • Yes
                      • BC-Programming.com
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Beginner
                    • OS: Windows 11
                    Re: How to cycle through numbers..?
                    « Reply #12 on: October 27, 2009, 07:04:40 AM »
                    well think about it- why use a Folder?

                    Why not use a file, say money.txt. Then you load the money amount with:

                    Code: [Select]
                    type money.txt | set /p %money%=

                    and retrieving the money amount would be:

                    Code: [Select]
                    echo %money%>money.txt
                    I was trying to dereference Null Pointers before it was cool.

                    Salmon Trout

                    • Guest
                    Re: How to cycle through numbers..?
                    « Reply #13 on: October 27, 2009, 07:26:30 AM »
                    When I were a lad (Northern English dialect) we used QBasic for these things.

                    DarrenReeder

                      Topic Starter


                      Rookie

                      Re: How to cycle through numbers..?
                      « Reply #14 on: October 27, 2009, 07:55:21 AM »
                      I understand why people say not to use Batch file for a game lke this...but im just making it on batch file because i wanna see what is possible using Batch files.....

                      --------


                      BC_Programmer, So it is possible to read from a txt file?  i didnt know you could read from them to be honest... is that what type does?