There's one thing you might have to think of. If you're going to do the event-checking/updates in functions (and you *want* that) then the functions must have access to those gadgets you created. ATM they're *not* globals. You can solve it with 3 methods:
(1) Make them global, it's the easiest solution, but not really recommended. The best applications have little or no globals at all
(2) put the function-calls in the mainloop and use the gadgets you need as function-arguements, not really recommended. The function-call only works in the mainloop then, and you might end-up with enourmous arguement-lists
(3) store all gadgets you created in 1 bank, and:
-- make this bank global
-- move this bank around as a function-arguement
I personally would prefer option 3 as it's the most clean and reusable option. It does require a little thinking tho.. but that doesn't hurt. :P
If you have 5 gadgets, like canvas1, canvas2, button, window, panel and you want to store them, do like this, before you call any functions.. so, at the start..
If you have a function Blah() and you need the button in there to check on events, do this:
Now you can call this function anywhere, with:
(ps, to call the function from anywhere, 'bank' must be a global.. *or* you already know 'bank' because you're in a function and 'bank' was already given to you as function-arguement)
Naturally, if you need more gadgets from your bank, you need to PeekInt, PeekShort, PeekByte, PeekFloat a bit more than that.. basically you Peek what you need.
If you change a value you just peeked, and you wish to keep that new value, you need to store it again ofcourse, with Poke.
(1) Make them global, it's the easiest solution, but not really recommended. The best applications have little or no globals at all
(2) put the function-calls in the mainloop and use the gadgets you need as function-arguements, not really recommended. The function-call only works in the mainloop then, and you might end-up with enourmous arguement-lists
(3) store all gadgets you created in 1 bank, and:
-- make this bank global
-- move this bank around as a function-arguement
I personally would prefer option 3 as it's the most clean and reusable option. It does require a little thinking tho.. but that doesn't hurt. :P
If you have 5 gadgets, like canvas1, canvas2, button, window, panel and you want to store them, do like this, before you call any functions.. so, at the start..
bank=Createbank(5*4) PokeInt bank, 0,canvas1 PokeInt bank, 4,canvas2 PokeInt bank, 8,button PokeInt bank,12,window PokeInt bank,16,panel
If you have a function Blah() and you need the button in there to check on events, do this:
Function Blah(bank) button=PeekInt(bank,08) ; and now the event-checking: If EventSource()=button ; do something here.. EndIf End Function
Now you can call this function anywhere, with:
Blah bank
(ps, to call the function from anywhere, 'bank' must be a global.. *or* you already know 'bank' because you're in a function and 'bank' was already given to you as function-arguement)
Naturally, if you need more gadgets from your bank, you need to PeekInt, PeekShort, PeekByte, PeekFloat a bit more than that.. basically you Peek what you need.
If you change a value you just peeked, and you wish to keep that new value, you need to store it again ofcourse, with Poke.