1

I'm coding a simple game and needed help,

pcash = user cash
reshp1 = cost to restore hp
php = player health

How do I write these into 1 line?

If user press 1, check if cash is equal or greater to the cost of restore hp, if it is greater - subtract cash base on cost of restore hp, then finally add the hp by 20%.

This is what I have tried, but did not work as expected.

if "%restorer%"=="1" if %pcash% geq %reshp1c% && set /a pcash=%pcash% - %reshp1c% && set /a php=%php% * .20

1 Answer 1

1
if "%restorer%"=="1" if %pcash% geq %reshp1c% set /a pcash=%pcash% - %reshp1c%&set /a php=%php%*6/5

& is used to separate cascaded statement. Batch uses integer mathematics, so *6/5 will multiply by 6 then divide by 5, adding 20% to the prior value (your code, had it worked, would have set the value to 20% of its prior magnitude)

Sign up to request clarification or add additional context in comments.

3 Comments

How many & can I use? And what if I have more than 3-5 if statements that I needed to add to the same line?
As many as you need. Why do you need to add them all on one line?
So I don't mix with other functions. I may also have other questions, but it's un-related to this topic. Am hoping you can help as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.