| View previous topic :: View next topic |
| Author |
Message |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Feb 05, 2004 7:29 pm Post subject: @random() or RANDOM |
|
|
Can someone help me with @random() or RANDOM:
I want to have my program go to 1 of the following labels at random:
:example-label-number1
<do something>
:example-label-number2
<do something>
:example-label-number3
<do something>
Seems it should be very easy for a VDSpro, hehe
Thanks in advance... |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Feb 05, 2004 7:36 pm Post subject: |
|
|
Hi vtol777,
Welcome to the forums and let me see if I can give you and example
here of what you need:
| Code: |
REM -- The following command just seeds the random
REM -- number generator.
RANDOM @name(@datetime())
REM -- The following function actually gets you the random
REM -- number. Two parameters in the function, first is the
REM -- lowest number you want to be able to return in the
REM -- random, and second the highest number you would
REM -- want returned.
%%RandomBranch = @RANDOM(1,3)
IF @equal(%%RandomBranch,1)
GOTO example-label-number1
ELSIF @equal(%%RandomBranch,2)
GOTO example-label-number2
ELSE
GOTO example-label-number3
END
GOTO EVENTLOOP
:EVENTLOOP
WAIT EVENT
%E = @event()
IF %E
GOTO %E
END
GOTO EVENTLOOP
:example-label-number1
<do something>
GOTO EVENTLOOP
:example-label-number2
<do something>
GOTO EVENTLOOP
:example-label-number3
<do something>
GOTO EVENTLOOP
|
_________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Feb 05, 2004 8:01 pm Post subject: |
|
|
Just make sure that you have all the necessary labels, otherwise if a
number is generated that doesn't correspond to a label, you'll get an error. _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Feb 05, 2004 8:24 pm Post subject: |
|
|
| I guess the random stuff has to be complex to work, I was hoping it would be simple without things in the Evloop - etc.., will that interfere or slow anything else down in my program(I'm gonna have to learn what its doing, hehe)? |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Feb 05, 2004 8:29 pm Post subject: |
|
|
Actually you can use the standard "evloop", Garrett posted a variation of
the standard one:
| Code: | :EVENTLOOP
WAIT EVENT
%E = @event()
IF %E
GOTO %E
END
GOTO EVENTLOOP |
You can use the following to do the same:
| Code: | :evloop
wait event
goto @event() |
_________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Feb 05, 2004 8:33 pm Post subject: |
|
|
I studied the Event stuff with what I had to study with, hopefully I'll tie it all together soon, thanks, the basic Evloop is what I'm used to...  |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Feb 05, 2004 8:37 pm Post subject: |
|
|
Sorry about that. We all kind of develop our own preferred habits (not
saying if they are good habits or bad!). I'm in the habit of checking the
%E from the event for when I need to capture an event, parse it and
then allow me to pick the final destination of the event. Unfortunately,
now I use that code even when it's not really needed, such as the
example above.
The random is not that complex, but if you are still a bit new to VDS, then
it may seem a bit complex at first until you've played with it a few times
and get the hang of it. It'll come to you quick enough.
Just take your time, run your code through the stepping in the IDE, watch
where the code goes etc.. Look at the code, verify the commands and
functions with the help file so you can try to understand what is going on
with things.
And of course, if all else fails... Just ask here at the forums. Trust
me, we don't bite... (Well, maybe once in a while.) _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Feb 05, 2004 8:37 pm Post subject: |
|
|
You'll eventually get it.
What Garrett's version does is put the event in a variable, and if there's
an event loaded in the variable it goes to the event, otherwise it loops
back.
With the basic event loop, it waits for an event, then when one comes along
it goes directly to the event.
Garrett's version is useful when you need more control over events, although
it will work for simple event handling too.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Feb 05, 2004 8:45 pm Post subject: |
|
|
| Would Garretts method help in situations where the Evloop goes back to labels (kinda double checking) when you dont really want it too? Maybe you helped me find a fix to another one of my problems, lol, triple dialog menu, where the program needs a Radio checked and to LIST box items selected before continuing, thanks... |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Feb 05, 2004 8:49 pm Post subject: |
|
|
Yes, exactly like FreezingFire said.
One example of this, is that I have a program that is an icon in the
system tray. This tray icon is a menu to launch programs. The
programs it gets are from two sources, the desktop shortcuts and
it's own folders and shortcuts.
Basically, what has to happen here, is that I have to dynamically generate
menu's. Now for me, I have well about 200 shortcuts in this little menu
system. Each having a MENU event. Mind you, I'm not in the mood to
try and generate 200 MENU branches, so instead, I use that EVENTLOOP
you see above, but I add a little code to it and find out what event has
just happened. IF it's one of the MENU events, then I send the event
to a special branch where I parse out the name of that menu event.
I'm not sure you understand what I mean on that. I'm not always very
good at trying to explain things.
Here's the EVENTLOOP of the program I am talking about:
| Code: | :EVENTLOOP
WAIT EVENT
%E = @event()
IF @greater(@pos(":"@tab(),%E),0)
GOTO MENUSELECTION
ELSIF @equal(%E,ExitMENU)@equal(%E,CLOSE)
GOTO CLOSE
ELSIF @equal(%E,TASKICON1CLICK)
GOTO TASKICON1CLICK
END
GOTO EVENTLOOP |
You see, I check the event to see if it has the ":" character in it. If
it does, it's one of my 200 some odd menu entries and I want to
send the event to the MENUSELECTION branch. The other code is
not really needed, but sometimes I add it in just in case I somehow
get some sort of stray events, which has happened to me in the past
when do things like this.
You know what. I'm probably tossing too much at you here. If you
catch the drift of the above, great, if not, don't bust your brain trying
to understand it yet. Just stick with working on your RANDOM code
for now. _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Thu Feb 05, 2004 9:01 pm Post subject: |
|
|
No not at all, Events was just one of the things I needed help with as Random.
I search string POS (positons) text, files and so on in some of my homemade utilitys at my website. So from what you've said is what I have been missing and needing, full control of event traffic, thanks again Garrett and also FreezingFire, appreciate it highly.
cheers |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Feb 05, 2004 9:08 pm Post subject: |
|
|
Well, if you need more help on that, and not so complex sounding, just
come back and let us know exactly what you are trying to do, and we'll
try to give you something as simple as possible. _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Fri Feb 06, 2004 3:31 am Post subject: |
|
|
Well, I was hoping I was doing something wrong, but after I edited your script a bit, it still just goes to the same label everytime.(I left out the Event section since I didnt need it where I needed the random lines)
%%RandomBranch = @RANDOM(1,3)
IF @equal(%%RandomBranch,1)
GOTO label2
ELSIF @equal(%%RandomBranch,2)
GOTO label3
ELSE
GOTO label3
END
goto skiplabels
:label1
:label2
:label3
:skiplabels
------------------------------------------------------
Heres what I had before(never worked either):
%%random_terrain_number = @RANDOM(3)
IF @equal(%%random_terrain_number,0)
goto label1
end
IF @equal(%%random_terrain_number,1)
goto label2
end
IF @equal(%%random_terrain_number,2)
goto label3
end
IF @equal(%%random_terrain_number,3)
goto label4
end
:label1
:label2
:label3
:label4
*I left out some technical things above in the labels to make the overall picture look easier. |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Fri Feb 06, 2004 3:34 am Post subject: |
|
|
oops
the second 'GOTO label3 ' should be 'GOTO label2 '
I goofed re-editing it on here, lol sorry |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Fri Feb 06, 2004 3:59 am Post subject: |
|
|
Try this:
| Code: |
RANDOM @datetime(ssnnss)
goto Label@RANDOM(3)
:Label0
INFO Label0
exit
:Label1
INFO Label1
exit
:Label2
INFO Label2
exit
|
_________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
|