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.

Simple random-script, please help me complete it

Old posts that have not been replied to for several years.
Locked
b
borys85
Voice
Posts: 1
Joined: Sun Dec 19, 2004 1:12 pm

Simple random-script, please help me complete it

Post by borys85 »

Hello!

We're playing RPG online (by IRC) and I need a script which can "simulate" dice. It has to do this: When user types "!result" it picks a random integer between 1-100 (1 and 100 included) and then it prints out the result of the action (as text) based on the picked number.

I think I managed to write the main part of this script. It looks like this:

Code: Select all

{
set number [rand 100]
set number [expr $string + 1]

if {$number > 0} then {set result "Critical failure"}
if {$number > 5} then {set result Very bad"}
if {$number > 15} then {set result "Bad"}
if {$number > 35} then {set result "Average"}
if {$number > 65} then {set result "Good"}
if {$number > 85} then {set result "Very good"}
if ($number > 95} then {set result "Critical success"}

puthelp "PRIVMSG $chan :Result... $result"
}
I think it's OK (is it?). I know I should have used "elseif", but Eggbot didn't recognize the command. Kinda strange...

Anyway, I know very little about Tcl. The script above does not work. It is missing proc-line and bind-line. Could you please tell me how they shall look like?

Thank you for your help
Borys
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

Code: Select all

bind pub - !result pubresult
proc pubresult { n u h c t } { 
  set number [expr {[rand 100]+1}] 
  if {$number < 5} {
    set result "Critical failure"
  } elseif {$number < 15} {
    set result "Very bad"
  } elseif {$number < 35} {
    set result "Bad"
  } elseif {$number < 65} {
    set result "Average"
  } elseif {$number < 85} {
    set result "Good"
  } elseif {$number < 95} {
    set result "Very Good"
  } else { 
    set result "Critical success" 
  } 
  puthelp "PRIVMSG $c :Result... $result ($number)" 
}
elseif is not a command but an argument to if

edit1&2: fixed broken english
photon?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

If you didn't understand the structure logic. Here it is to make it simpler. Basically, the structure is like:

Code: Select all

proc myproc {n u h c t} {
 if {....} { #do stuff }
 elseif {....} { #do stuff }
 elseif {....} { #do stuff }
 elseif {....} { #do stuff }
 else { #do stuff }
}
{....} being the condition to satisfy. Remember "else" will have no condition to satisfy as it will be your last choice, saying your last resort, if every condition before it does not satisfy and run, then else will do the job.

Or you can do a similar thing with alot of "if's" and it will still work as well. But note this one does not have an "else". So if the conditions are satisfied they will run, otherwise they wont. Generally this type of structure is used if more than one condition is true; for multiple conditions.

Code: Select all

proc myproc {n u h c t} {
 if {....} { #do stuff }
 if {....} { #do stuff }
 if {....} { #do stuff }
 if {....} { #do stuff }
 if {....} { #do stuff }
}
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

proc myproc {n u h c t} {
if {....} { #do stuff }
if {....} { #do stuff }
if {....} { #do stuff }
if {....} { #do stuff }
if {....} { #do stuff }
}
this will trigger all the elseif will end on the first condition it meets

for example lets say the number is 5 then $number is smaller then 35 but also smaller then 65 !!!!!

same with bigger if number is 60 then it is bigger then 30 and bigger then 10 .. so thats why elseif it will enter the first condition it meets and not go on any further unless you use return on the end of the if statement ..

Code: Select all

if {....} { 
  #do stuff 
   return
}
if {....} { 
  #do stuff 
  return
}
if {....} { 
  #do stuff 
  return
}
if {....} { 
  #do stuff 
  return
}
if {....} { 
  #do stuff 
  return
}
XplaiN but think of me as stupid
Locked