If you want modulear non linear code, go OOP

(in purebasic if you want to. or praise fred to build some basic class support in. Perhaps he will listen one day

)
Or use goto's a lot.
You can also use gosub and return as a simple procedure. I guess it has slightly less memory overhead and is a little faster... (for optimizer freaks.. but perhaps im not right.)
procedures got some other advantages but if you REALLY are an optimizing freak i would wonder if using GOTO's or gosub/return would work...
perhaps someone can test it?
goto example:
Code: Select all
;jump the code over.!
Goto main
;********************************
;"function" one.. using goto and RET
ShowAbout:
MessageRequester("About!","This little example is programmed by me!")
RET ;RET will now jump back to the address last stored in the stack!
;********************************
;********************************
;"function" two. using gosub
PrintThing:
PrintN("Now im in my gosub!")
Return ;Return.
;********************************
main:
;main code:
OpenConsole()
;Calling function one and returning..
PrintN("Going to show about using goto's and gosubs.")
PUSH l_back ;Pushing the address of the label back into the stack.
Goto showabout
back:
PrintN("Now im back!")
Input()
PrintN("Running into my second function!")
Gosub printthing ;Perhaps this is just pushing a hidden label to the stack like above code?
PrintN("back!")
Input()
edit: just thought i would say this; The use of using RET to jump to code positions can annoy some disassemblers. wich is good

I've even made examples where they wouldnt find the code and so on. Also, the crackers don't know the place to jump sometimes

How? Because you can push like you want to. You can push anywhere, just as long as you don't change the stack. You can use it in an if loop.
if serial="blah"
push ?goodlocation
else
push ?badlocation
endif
;perhaps do something. jump somewhere, then perform a RET!