This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

using chances when setting variables with random

Old posts that have not been replied to for several years.
Locked
k
kompak

using chances when setting variables with random

Post by kompak »

A while ago a made a tcl script that does this:
1. pick a random number
2. assign a certain value to a variable according to the number

This is what I came up with:

Code: Select all

set foo [random 9]
 if {$foo >= 0 && $foo <= 2} { set bar "something" } 
 if {$foo >= 3 && $foo <= 6} { set bar "something else" } 
 if {$foo >= 7 && $foo <= 9} { set bar "something completely different" }
Now I know this is propably the worst way of doing this sort of thing, but it worked all right. Until now when I would need to change the chances of the values easily with variables. Lets say I want to change the chances of the first one to 0-4. If I just do that without altering the rest of the script it will completely mess it up.
I have thought about alternative ways but since I'm quite new to tcl it just makes my head hurt :)
I also searched the forums but couldn't find anything helpful.
Any help will be appreciated.

[EDIT: typos and stuff]
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

I didn't clearly understand what you are trying to say and what your question was. Please state it clearly, what do you want the script to do (PURPOSE/OUTPUT)?
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked