RCRPG/Tcl: Difference between revisions

Content added Content deleted
(Minor improvements for readability)
m (style improvement: put expressions in braces)
Line 33: Line 33:
proc Room {xyz {name {}} {items {}}} { #-- "constructor"
proc Room {xyz {name {}} {items {}}} { #-- "constructor"
if {$name eq ""} {set name R.[incr ::R()]}
if {$name eq ""} {set name R.[incr ::R()]}
if ![llength $items] {set items [lpick {sledge {} ladder gold}]}
if {![llength $items]} {set items [lpick {sledge {} ladder gold}]}
array set ::R [list $xyz.name $name $xyz.items $items $xyz.exits {}]
array set ::R [list $xyz.name $name $xyz.items $items $xyz.exits {}]
}
}
Line 81: Line 81:
}
}
set exits $::R($xyz.exits)
set exits $::R($xyz.exits)
if ![llength $exits] {set exits nowhere}
if {![llength $exits]} {set exits nowhere}
puts "There are exits towards: [join $exits {, }]"
puts "There are exits towards: [join $exits {, }]"
inventory
inventory
Line 112: Line 112:
}
}
set xyz $x,$y,$z
set xyz $x,$y,$z
if ![info exists ::R($xyz.name)] {Room $xyz}
if {![info exists ::R($xyz.name)]} {Room $xyz}
set ::Self(coords) $xyz
set ::Self(coords) $xyz
if $describe describe
if {$describe} describe
}
}


Line 147: Line 147:
}
}
proc pretty lst {
proc pretty lst {
if ![llength $lst] {return nothing}
if {![llength $lst]} {return nothing}
foreach i $lst {lappend tmp "a $i"}
foreach i $lst {lappend tmp "a $i"}
regsub {(.+),} [join $tmp ", "] {\1, and}
regsub {(.+),} [join $tmp ", "] {\1, and}
Line 261: Line 261:
}
}
set exits [@ here exits]
set exits [@ here exits]
if ![llength $exits] {set exits nowhere}
if {![llength $exits]} {set exits nowhere}
puts "There are exits towards: [join $exits {, }]."
puts "There are exits towards: [join $exits {, }]."
inventory
inventory
Line 292: Line 292:
return "No exit towards $where, consider an attack..."
return "No exit towards $where, consider an attack..."
}
}
if [catch {@ $coords name}] {Room $coords}
if {[catch {@ $coords name}]} {Room $coords}
@ my coords $coords
@ my coords $coords
if $describe describe
if {$describe} describe
}
}


Line 322: Line 322:
}
}
proc pretty lst {
proc pretty lst {
if ![llength $lst] {return nothing}
if {![llength $lst]} {return nothing}
foreach i $lst {lappend tmp [expr {$i eq "gold"? $i : "a $i"}]}
foreach i $lst {lappend tmp [expr {$i eq "gold"? $i : "a $i"}]}
regsub {(.+),} [join $tmp ", "] {\1, and}
regsub {(.+),} [join $tmp ", "] {\1, and}