forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


@random() or RANDOM
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Thu Feb 05, 2004 7:29 pm    Post subject: @random() or RANDOM Reply with quote

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
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Feb 05, 2004 7:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu Feb 05, 2004 8:01 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Thu Feb 05, 2004 8:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu Feb 05, 2004 8:29 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Thu Feb 05, 2004 8:33 pm    Post subject: Reply with quote

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... Smile
Back to top
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Feb 05, 2004 8:37 pm    Post subject: Reply with quote

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. Smile

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. Smile Trust
me, we don't bite... Twisted Evil (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
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu Feb 05, 2004 8:37 pm    Post subject: Reply with quote

You'll eventually get it. Smile

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. Smile

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Thu Feb 05, 2004 8:45 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Feb 05, 2004 8:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Thu Feb 05, 2004 9:01 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Feb 05, 2004 9:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Fri Feb 06, 2004 3:31 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Fri Feb 06, 2004 3:34 am    Post subject: Reply with quote

oops

the second 'GOTO label3 ' should be 'GOTO label2 '

I goofed re-editing it on here, lol sorry
Back to top
View user's profile Send private message Visit poster's website
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Feb 06, 2004 3:59 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group