Page 1 of 1

What is the idea with Add(), Div() etc.?

Posted: Wed Mar 05, 2025 11:07 am
by Bugala
I thought that using X = Add(x, 1) would be faster that using x = x + 1, but seems I was wrong:

Code: Select all

amount = 100000
x = 1000
y = 1000
a = 1000
b = 1000
c = 1000

StartTimer(1)
start = GetTimer(1)
For n = 0 To amount
x = Add(x, 1)
y = Add(y, 1)
a = Add(a, 1)
b = Add(b, 1)
c = Add(c, 1)
Next

Endtime = GetTimer(1)

timepassed = Endtime - start
TextOut(10, 10, "add time:"..timepassed)

start = GetTimer(1)
For n = 0 To amount
x = x + 1
y = y + 1
a = a + 1
b = b + 1
c = c + 1
Next

endtime = GetTimer(1)
timepassed = endtime - start
TextOut(10, 100, "x+x time:"..timepassed)

WaitLeftMouse()
Resulting on my machine:
add time: 66
x + x time: 45

Which makes me wonder what is the point with those Add(), Div() etc. commands, if they just make the program slower, and are not as handy to use as x = x+1?

Re: What is the idea with Add(), Div() etc.?

Posted: Wed Mar 05, 2025 10:29 pm
by airsoftsoftwair
These are old functions from the days of Hollywood 1.x. They are just there for compatibility with old scripts. You shouldn't use them in new code because they will be much slower than using operators because their use involves a function call while operators will directly map to VM opcodes.