LoginLogin
Might make SBS readonly: thread

Def/end tutorial

Root / Submissions / [.]

randoCreated:
Hey! Welcome to my tutorial! Here we will be talking about user-defined instructions. User-defined instructions act kind of like gosub, excep you can add arguments and make your own codes! Well, lets start already! User-defined instructions with no arguments Yes, all of these use the def command. This is the section for the basics. Yay. Here are some rules for def: 1. You can't have a def in a def. Example:
DEF
DEF
END
END
will give you an error. 2. Def has to end with end. If it doesn't, the program won't know where to stop. 3. You probably want something in the def, if you don't it is useless. With def you just put def then the name of the instruction. Then the code and end. I would not recommend putting end in the middle of a def/end code. Here are some screenshots: Simple def/end Less simple def/end User instructions with arguments but no return values The section above with arguments. Yay. Arguments help define the outcome. Sure, you can have inputs in the def, but this is easier. Screenshots: Simple Def/end with arguments More complex Def/end with arguments Note that the complex call has quotation marks on the third argument. That is because I used a string variable in defining on the third argument. If you don't know, normal variables can be used like V1, but string variables have a $ after them, like V1$. So that was my tutorial, I'll try to learn the one with return values. After that, I will hopefully remember this and update it. Thank you for reading!

The $ can be omitted in the CALCULATE DEFiniton as the DEF command does not directly check the variable types inside the definition:
So you can do something like this
'calculate the middle
Def MID(X,M,B)'M can be M$ too
Return X-LEN(M)*(B/2)
End
Print MID(200,"dummy",8)'returns 180
rem.calling.the.function.with.PRINT/?
EDIT: These with return values can be:
DEF MID(X,S,W)
'usable with PRINT, etc.
'Only 1 return value
'Format: V=MID(X,S,W)
DEF RIGHT X,S,W OUT V1,V2,...
'cannot be used in PRINT, etc.
'You can set as many return values as you need from the DEFined instruction at once
'Format: RIGHT X,S,W OUT V1,V2,...
Also: COMMON DEF Usable even if that DEFinition is in a different slot. (Use USE to use the COMMON DEFs in that slot. Regular DEFs won't be usable.