How To

Can we return a value in a SUB like in C ?

0

G-9 2020-10-28 08:19


qwaffe 2020-10-28 08:49 (Edited)

something like

R=0

SUB ADD(A,B,X)
X=A+B
END SUB

CALL ADD(2,3,R)

I think that would set R to 5, still better than using a global variable.
But I'm pretty sure you can't do them inline


was8bit 2020-10-28 11:15

Yes, after your call, R will be 5

You have to have set R already, like R=0, just to initialize the variable or you will get an error for that


was8bit 2020-10-28 11:20

Another tip, you could also do CALL IADD(1,2,3) and you will not get an error message..

You can also do CALL IADD(RND(10),Y,Z)

...notice i use IADD as ADD is already a command ;)


was8bit 2020-10-28 11:24 (Edited)

This really makes SUB very powerful, as you can reuse it... for example...

CALL SUB IADD(xplayer,yplayer,zplayer)

Then

CALL SUB IADD(xenemy,yenemy,zenemy)

So, inside the parenthesis, you can use any Value, any Variable, or any piece of Math that resolves into a value... all are acceptable :)


qwaffe 2020-10-29 00:32 (Edited)

forgot that ADD is already a command oops
oh well, at least it isnt an error


Log in to reply.