Game help,if player has money smaller than cost of something

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
silent
Posts: 44
Joined: 28 Oct 2011 14:40

Game help,if player has money smaller than cost of something

#1 Post by silent » 09 Jan 2012 10:22

As u know im creating a game,and in this game is a shop.But i want to make it that if players money is 360$,and something is for 370,player will get text "You dont have enough money to buy this item".Money is saved to a file GSETS.db and is readed by

Code: Select all

pushd "%temp%"
if exist "GSETS.db" (
   FOR /F "tokens=1,2 delims==" %%A IN (GSETS.db) DO (
      if "%%A" == "Level" set Level=%%B
      if "%%A" == "Money" set Money=%%B
      if "%%A" == "Nickname" set nickname=%%B
   )
   set FirstPlay=0
)


and then it detects if player has already played the game,and teleports him to level that is in GSETS.db with money and nickname that is located in that file 2.

I thought about using IF but i know only standard commands of batch,and i dont know how to create command like this.
Thanks in advance

aGerman
Expert
Posts: 3886
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Game help,if player has money smaller than cost of somet

#2 Post by aGerman » 09 Jan 2012 12:23

Save only the numeric value (without currency).
Now use an IF statement with comparison operator GTR (greater than) or LSS (less than) and don't enclose numeric values in quotation marks (otherwise they are compared as strings).

Regards
aGerman

silent
Posts: 44
Joined: 28 Oct 2011 14:40

Re: Game help,if player has money smaller than cost of somet

#3 Post by silent » 10 Jan 2012 09:22

Could u post that code for me ? Im totally newb,i know only standard commands
//
I think i made it good,is it good ?

Code: Select all

IF %Money% LSS 50 Echo You dont have enough money to buy this item.
but when i try to buy something thats for 500$ (and i have 200$) it buys it,i dont know where to put it,heres code of buying in shop

Code: Select all

set /p buyitem=

IF %Money% LSS 50 Echo You dont have enough money to buy this item.
if %buyitem% ==1 goto blah
if %buyitem% ==2 goto 234234
if %buyitem% ==3 goto 234324234324
if %buyitem% ==4 goto 324324
if %buyitem% ==5 goto 234232
if %buyitem% ==6 goto 3523
if %buyitem% ==7 goto 43
if %buyitem% ==8 goto fkds
if %buyitem% ==9 goto gsdgdsg
if %buyitem% ==10 goto asfgsa

the fasfsa things are made because i used them only for test
// Oh i understand why it doesnt work,because i havent set what item costs how much money,but how to do it ?
//Fixed,i forget that every items cost is different.Added IF %Money% LSS (here cost of item) goto nomoney

:nomoney
echo You dont have enough money to buy this item
pause

Squashman
Expert
Posts: 4176
Joined: 23 Dec 2011 13:59

Re: Game help,if player has money smaller than cost of somet

#4 Post by Squashman » 10 Jan 2012 10:07

Does your MONEY variable have a currency symbol in it or not? If it does you need to remove it from the variable in order to compare the two values.

I am no math major but I am pretty sure 50 is not the same as 500.

Code: Select all

IF %Money% LSS 50 Echo You dont have enough money to buy this item.

And IF this statement is TRUE you would probably want to use a GOTO to move to a different part of your code otherwise it is going to process all those IF statements to buy an item.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Game help,if player has money smaller than cost of somet

#5 Post by Ed Dyreen » 10 Jan 2012 19:37

'
Squashman wrote:And IF this statement is TRUE you would probably want to use a GOTO to move to a different part of your code otherwise it is going to process all those IF statements to buy an item.
True, I don't even understand why goto is used like this on an XP or above.

Code: Select all

:While the proper use of goto
if 1 equ 1 (
) else if 1 equ 0 (
) else if "bla"=="blabla" (
) else bla bla bla
%Sleep% 100ms %= unstress CPU =% &goto :While
:roll:

Post Reply