1.

Solve : Arithmetic Operators?

Answer»

God, how many probelsm can I get Dx.
I have trouble with the arithmetic operators. Can you please try to fix this example piece of code (I was going to make a practice project for my batch game making). I can't get it to loop, so when %playerhp% is 3, it stays 3 even though I made it do the same thing twice (yes, I know its rigged). Code:
Code: [Select]echo off
:MAIN
:: THIS PART WORKS, BUT THE FIGHT PARTS DON'T
set counter=2
set plus=1
set minus=1
set multiply=2
set divide=2
echo Your number is %counter%.
set /a counter=%counter%+%plus%
echo Now your number is %counter%
set /a counter=%counter%-%minus%
echo Now your number is %counter%
set /a counter=%counter%*%multiply%
echo Now your number is %counter%
set /a counter=%counter%/%divide%
echo Now your number is %counter%
goto FIGHT
:FIGHT
cls
set playerhp=10
set playerattack=3
set monsterhp=5
if %monsterhp% LEQ 0 goto MONSTERDEAD
set monsterattack=2
echo You hit the monster for %playerattack%
set /a monsterhp=%monsterhp%-%playerattack%
echo Now the monsters hp is %monsterhp%
pause
goto PLAYERFIGHT
:PLAYERFIGHT
echo The monster hits your for %monsterattack%
set /a playerhp=%monsterhp%-%playerhp%
echo Now your HP is %playerhp%
pause
goto FIGHT2
:FIGHT2
cls
set playerhp=10
set playerattack=3
set monsterhp=5
if %monsterhp% LEQ 0 goto MONSTERDEAD
set monsterattack=2
echo You hit the monster for %playerattack%
set /a monsterhp=%monsterhp%-%playerattack%
echo Now the monsters hp is %monsterhp%
pause
goto PLAYERFIGHT2
:PLAYERFIGHT2
echo The monster hits your for %monsterattack%
set /a playerhp=%monsterhp%-%playerhp%
echo Now your HP is %playerhp%
pause
goto FIGHT
:MONSTERDEAD
echo The monsters dead!!!
pause
goto EXIT
:EXIT
cls
pause
exit
too LONG ... Quote from: Prince_ on February 21, 2010, 08:23:25 PM

too long ...
Well, that's useful.

These lines:

echo You hit the monster for %playerattack%
set /a monsterhp=%monsterhp%-%playerattack%

Really should go before this line:
if %monsterhp% LEQ 0 goto MONSTERDEADGod, _Prince, you should see my other "experiments" and my other training things. Quote from: tommyroyall on February 22, 2010, 05:06:17 PM
God, _Prince, you should see my other "experiments" and my other training things.
Yes _Prince, you really should. Tommy must love jumping into the deep end before learning the "doggie paddle". Quote from: tommyroyall on February 20, 2010, 07:56:02 PM
God, how many probelsm can I get Dx.
go to here and learn the stuff.(take the tutorial). Then when you are ready, go to here and try making your game. problem solvedI really do love insane problems. You should see my other experiments, they're INSANE (but I'm not showing you). I have much, MUCH more advanced knowledge than you guys think I do, just not with batch  . I can't BELEIVE that I've been having trouble with my arithmetic operators. It's like this specific program didn't work, but a bank type of one that I made did. I wonder if it's to do with something inside of it. I have an idea for a scripting language called APPL using all of my knowledge, but does anyone know if I could make a programming language with a program (like where it takes the input and makes the code). Quote
I have an idea for a scripting language called APPL using all of my knowledge
I'd suggest you think of a name that isn't already taken.

Quote from: tommyroyall on February 24, 2010, 07:34:13 PM
but does anyone know if I could make a programming language with a program (like where it takes the input and makes the code).

How the heck do you think programming languages were made? they just sorta appeared? they had to be written in something. the VBScript Interpreter is written in C/C++... but I wrote a slow VBScript interpreter in VB6. FreeBASIC is written in FreeBASIC... ALSO, Microsoft Visual Studio 6, For example, was written with Microsoft Visual Studio 5.

Quote
I have much, MUCH more advanced knowledge than you guys think I do, just not with batch

Then with what?

Quote
I can't beleive that I've been having trouble with my arithmetic operators. It's like this specific program didn't work, but a bank type of one that I made did. I wonder if it's to do with something inside of it.
I'm not even sure what your saying here, so I'll just nod enthusiastically *nods enthusiastically*



Quote from: tommyroyall on February 24, 2010, 07:34:13 PM
I have much, MUCH more advanced knowledge than you guys think I do

Really?
I spend my life on a computer (yet, I don't think it's wasted  ) and I study them ALL THE TIME. I have resources on development for tablet PCs, C++, HTMl, JavaScript, ASP, PHP, CSS, XMl, XHTML, CGI, Perl and HTTP. I've always liked web development more than programming, but I still learn a little bit. (could I still use the tablet PC development book for a normal PC?).Then why this ? ? ?

Quote
I know that %variables_have_percent_marks% but what %%is_this? is it also a variable?
hahaha

Quote
I have resources on development for tablet PCs, C++, HTMl, JavaScript, ASP, PHP, CSS, XMl, XHTML, CGI, Perl and HTTP


First: having resource on development for something is far from understanding the content of that resource.

Tablet PC development is the same as any other PC. It's a PC. You cannot "develop" with XML, since it's not a programming language, Nor is CGI, which is merely a method of executing a Server Side Executable, And HTTP is a bloody network PROTOCOL, so I hardly see how you could develop with  it.

Also Patio raises the interesting point that your questions bear little discourse for your current claims.

lastly, one with  knowledge of such extensive topics would probably be able to look at the documentation for batch and find what your looking for.

Your demeanour and the fact that the batch you posted resembles an attempt at a game tell a lot more then your claims of grandeur could.Dude, when I say resources I mean That I've read and used. Quote from: tommyroyall on February 26, 2010, 07:10:16 PM
When I say resources I mean That I've read and used.

A variable is a location in RAM ( Random Access Memory ) where a value ... a number or text is stored. All information in RAM is removed when the computer is shutdown.

If variable is the name of the location, then echo  %variable% displays the value stored at the location.
set /a variable = %variable% +  1  adds 1 to value stored at the variable location.

set /a variable = %variable% *  3 multiplies the value stored at variable by 3

All the arithmetic operators work in the same  manner.

for example:


C:\batch>type  tom2.bat
Code: [Select]echo off

set /a variable=3
echo variable = %variable%
set /a variable=%variable% +  1
echo variable plus 1 =%variable%
set /a variable=%variable% *  3
echo variable times 3 = %variable%
Output:

C:\batch>tom2.bat
variable = 3
variable plus 1 =4
variable times 3 = 12

C:\batch> Quote from: tommyroyall on February 20, 2010, 07:56:02 PM
Arithmetic Operators?
Code: [Select][/quote]



C:\batch>type tom2.bat

echo off

set /a variable=3
echo variable = %variable%
set /a variable=%variable% +  1
echo variable plus 1 = %variable%
set /a variable=%variable% *  3
echo variable times 3 = %variable%

set /a variable=%variable% +  1

echo variable plus 1 = %variable%

set /a variable=%variable% /  3

echo variable divide by  3 = %variable%

set /a variable=%variable% +  1

echo variable plus 1 =%variable%

set /a variable=%variable% /  3

echo variable divide by  3 = %variable%


C:\batch> tom2.bat
variable = 3
variable plus 1 = 4
variable times 3 = 12
variable plus 1 = 13
variable divide by  3 = 4
variable plus 1 =5
variable divide by  3 = 1
C:\batch>

p.s.: Is 13/3  = 4 ?
        Is 5/3 = 1 ?


Discussion

No Comment Found