Posts: 442
Threads: 107
Joined: Feb 2005
why does this not work?
Code:
option explicit
declare sub message_selector(a)
declare sub message_one(message)
declare sub message_two(message2)
dim a as integer
dim message as string
dim message2 as string
message = "what the f***"
message2 = "stfu!"
randomize timer
goto message_selector(a)
sub message_selector(a)
do
a = rnd * 3
if a = 1 then goto message_one(message) end if
if a = 2 then goto message_two(message2) end if
loop
end sub
sub message_one(message)
print message
goto message_selector(a)
end sub
sub message_two(message2)
print message2
goto message_selector(a)
end sub
url=http://www.random-seed.net]
[/url]
remove all gotos.
if you HAD to you could use CALL, thats proper syntax for ... calling :p a sub. but call is just empty baggage, like LET.
also, message_selector doesnt need to be passed ( a ), its never passed back. just dim a within the sub instead
Posts: 442
Threads: 107
Joined: Feb 2005
yeah, whats with the dim shared?
url=http://www.random-seed.net]
[/url]
Posts: 442
Threads: 107
Joined: Feb 2005
ok, here we go, i revized the entire thing...
Code:
option explicit
randomize timer
declare sub message()
declare sub message_two()
declare sub message_selector()
message_selector
sub message_selector()
dim sub_pointer as integer
do
sub_pointer = rnd * 3
if sub_pointer = 1 then call message() end if
if sub_pointer = 2 then call message_two() end if
sleep 500
loop
end sub
sub message()
print "WTF"
call message_selector()
end sub
sub message_two()
print "stfu"
call message_selector()
end sub
is that pretty good? the point of the exersize is to make a program that selects random subs
url=http://www.random-seed.net]
[/url]
the subs cant acess module level variables. so, your flow is like this
main -> message_selector -> message
all the stuff is in main, but once u get to msg selector, you lose all those main variables (except SHARED or passed vars). thats called "scope"
to recap, shared lets all subs acess those messages without having to pass them
Posts: 442
Threads: 107
Joined: Feb 2005
aaah! wow, thas really kool... so if i want to use the variable "A" in my mainloop, and in sub1 and sub2, i could dim it as shared, then there you go? wow... pretty freakin sweet
url=http://www.random-seed.net]
[/url]
Posts: 442
Threads: 107
Joined: Feb 2005
i kinda see whats happening there, but i dont think i'm at the level of using that in my code... i'm not a jedi yet
url=http://www.random-seed.net]
[/url]
for future reference ;)
its extremely handy for handling states, instead of like select case case 1 (code) case 2 (code) ... case 78 (code) lols. u can just set pointers like i did, and then call the sub number with the code in it.