| View previous topic :: View next topic |
| Author |
Message |
cerberus_gr Halfop
Joined: 07 Feb 2003 Posts: 97 Location: 127.0.0.1
|
Posted: Sat Jun 24, 2006 9:11 am Post subject: Help about strings and lists |
|
|
Hello,
I 'm writing a scrable game and I have some problem about strings and lists.
I have a mysql database where all questions and answers exist. I don't insert the questions myself, so maybe questions have invalid characters such as {, }, [, ].
The problem is where do I need to use [join], [concat], [list] commands in order not to have problems.
A part of my code is the following
| Code: |
# Comments:
# chid = channel's id from the database
# mysql::sel returns "{Album of John} {Hello world} 1 {Music}"
# gamebot:scrable:translate procedure needs to convert greek characters to english
proc gamebot:scrable:round:new { chid } {
global gamebot gamebot_scrable
# Variables
incr gamebot_scrable(round_$chid) 1
# Read data from the database and creates the variables
set query "SELECT qhint,qanswer,cid,cname FROM questions,categories WHERE qchid=$chid"
set data [mysql::sel $gamebot(mysql) $query -flatlist]
set hint [gamebot:scrable:translate $chid [lindex $data 0]]
set answer [gamebot:scrable:translate $chid [lindex $data 1]]
set categid [lindex $data 2]
set categname [gamebot:scrable:translate $chid [lindex $data 3]]
# ERROR OVER HERE :(
#set answer_scrabled [gamebot:scrable_scrablefrase $answer]
set gamebot_scrable(answer_$chid) $answer
set gamebot_scrable(categid_$chid) $categid
set gamebot_scrable(qstart_$chid) [clock clicks -milliseconds]
# Creates the binds
bind pubm - * gamebot:scrable_msg
# Send the message to the channel
gamebot:putmsg [gamebot:gettext $chid "SCRABLE_ROUND_NEW" "<round> $gamebot_scrable(round_$chid) <category> $categname <rounds> $gamebot_scrable(rounds_$chid)"]
gamebot:putmsg [gamebot:gettext $chid "SCRABLE_HINT" "<hint> $hint"]
gamebot:putmsg [gamebot:gettext $chid "SCRABLE_ANSWER" "<answer> $answer"]
}
proc gamebot:scrable:translate { chid args } {
set args [string map {"Ου" "Ou" "Α" "A" "Ά" "A" "Β" "B" "Γ" "G" "Δ" "D" "Ε" "E" "Έ" "E" "Ζ" "Z" "Η" "I" "Ή" "I" "Θ" "Th" "Ι" "I" "Ί" "I" "Κ" "K" "Λ" "L" "Μ" "M" "Ν" "N" "Ξ" "Ks" "Ο" "O" "Ό" "O" "Π" "P" "Ρ" "R" "Σ" "S" "Τ" "T" "Υ" "Y" "Ύ" "Y" "Φ" "F" "Χ" "X" "Ψ" "Ps" "Ω" "O" "Ώ" "O"} $args]
set args [string map {"ου" "ou" "α" "a" "ά" "a" "β" "b" "γ" "g" "δ" "d" "ε" "e" "έ" "e" "ζ" "z" "η" "i" "ή" "i" "θ" "th" "ι" "i" "ί" "i" "κ" "k" "λ" "l" "μ" "m" "ν" "n" "ξ" "ks" "ο" "o" "ό" "o" "π" "p" "ρ" "r" "σ" "s" "ς" "s" "τ" "t" "υ" "y" "ύ" "y" "φ" "f" "χ" "x" "ψ" "ps" "ω" "o" "ώ" "o"} $args]
return $args
}
proc gamebot:scrable_scrableword { str } {
# Variables
set len [string length $str]
set nstr ""
while {$len > 0} {
set num [format %.0f [expr {rand() * ($len - 1)}]]
append nstr [string index $str $num]
set str [string replace $str $num $num]
incr len -1
}
return $nstr
}
proc gamebot:scrable_scrablefrase { str } {
# Variables
set words [regexp -all {\s} $str]
set i 0
set nstr ""
while {$i <= $words} {
lappend nstr [gamebot:srable_scrableword [join [lindex [split $str] $i]]]
incr i
}
return [join $nstr]
}
|
Please help.
Thanks |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Sun Jun 25, 2006 12:34 am Post subject: |
|
|
you won't have any problems and you don't need to strip those chars as long as you simply output db text and don't pass it to proc's which do evaluation _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
|
|
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
|
|