Post new topic    
Red Slime
Send private message
plotscript problem, solution and question 
 PostThu Aug 07, 2014 4:42 am
Send private message Reply with quote
For me, the ohr is the game. When I want to do something it creates a problem and the game is finding a solution. But this one puzzles me.

Here is the code.
Code:
if (speedUp < -playerSpeed) then (speedUp := -playerSpeed)


The compiler says "-playerSpeed" has not been defined.
Okay. So my solution is...
Code:
if (speedUp < playerSpeed -- (playerSpeed * 2)) then (speedUp := playerSpeed -- (playerSpeed * 2 ))


Problem solved.
But here's my question.
Shouldn't I be able to give a variable a negative value by placing a "-" in front of it because I can do it with numbers and a variable is just representing a number?
And was there a better way of solving this problem?

Thanks for your help!
Metal King Slime
Send private message
 
 PostThu Aug 07, 2014 9:07 am
Send private message Reply with quote
The problem is that HamsterSpeak doesn't have the negation operator, -. Negative numbers are a special case, they're not actually the negation operator applied to a positive number (which is technically the case in most other programming languages). You can either write 0 -- x or -1 * x instead of -x.

I really would like to add both a negation operator (not really needed), and an alternative spelling of - instead of -- for subtraction, but it isn't really possible to add it in a back-compatible way without something like requiring you declare "from future import minus" at the top of the file...
Red Slime
Send private message
 
 PostThu Aug 07, 2014 9:30 am
Send private message Reply with quote
That explanation makes sense.
And your two ways of handling it were simpler than mine.
I learned things today. Thank you TMC
Display posts from previous: