• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Rounding Code Errors

Status
Not open for further replies.
Level 8
Joined
Jul 9, 2006
Messages
41
I was trying to write a function to round out numbers, and I came up with this:

function RoundTo takes real roundee, integer decimalplace returns integer rounded
local string a = R2S(roundee)
local string b
local integer product
if S2I(Substring( a, StringLength(a), StringLength(a) )) >=6 then
set b = SubString( a, 1, StringLength(a)-decimalplace-1 )+I2S(S2I(Substring( a, StringLength(a)-decimalplace, StringLength(a)))+1)+"0"
else
set b = Substring( a, 1, StringLength(a)-decimalplace ) +"0"
endif
set product = S2I(b)
return product
endfunction


It keeps giving me a syntax error on the first line, and I can't figure out why. Because of this, I have no clue whether it will work or not. Help!!!
 
Level 11
Joined
Oct 13, 2005
Messages
233
It keeps giving me a syntax error on the first line.
That's right. You only specify a return type, not a name for it. Think for a second, what's the point in having the return value have a name? For the parameters, it's so you can refer to them.

As for some further help, what are you trying to do with that function? If you're trying to round a real value properly, just add .5 to it and convert it to an integer. Also, you're using the SubString function incorrectly. You're using it like SubStringBJ, you need to subtract 1 from the first value instead.
 
Status
Not open for further replies.
Top