Jumping to one proc after another

Old posts that have not been replied to for several years.
Locked
User avatar
Tristam
Voice
Posts: 17
Joined: Sun Sep 21, 2003 11:28 am
Location: Finland

Jumping to one proc after another

Post by Tristam »

Yello! I would like to ask if there is a command in tcl similiar to "go to" or "then"..? Let me explain:

I have a simple script:

Code: Select all

proc topic_set { nick host hand chan text } { 
set fileid [open tristam-topic_theme.txt r]
gets $fileid topic_theme
close $fileid
  if {$topic_theme == "1"} {
set t_start "7,1.::"
set t_colour "15"
set t_middle "7::"
set t_end "7::."
  } elseif {$topic_theme == "2"} {
set t_start "1,14.::"
set t_colour "0"
set t_middle "1::"
set t_end "1::."
  } elseif {$topic_theme == "3"} {
set t_start "7,1» 0» 7»"
set t_colour "7"
set t_middle "7«0?7»"
set t_end "7« 0« 7«"
 } }
See, it opens up a file and reads the value (which is set with a different command before, and sets the t_xxx variables according to what the value in the file is, understood? good :)) So, I want it to "move" along with the script, or just "move" to another proc, which does the rest. I could fix it by typing the rest of it after each 1,2,3 varible chack commands, but that would make my code 47834786 lines long and stupid :)

So what I really want to know it: Is there a way to "jump" or "move" to another proc after finished the other? Or a command like "then". I hope you understand ;)

Here is the rest of the code btw, if anyone is interested what am I trying to do :>

Code: Select all

set fileid [open tristam-topic_sections.txt r]
gets $fileid topic_sections
  if {$topic_sections == "0"} {
puthelp "PRIVMSG $chan :There is no topic set in $chan!"
 } elseif {$topic_sections == "1"} {
set fileid [open tristam-topic_1.txt r]
gets $fileid topic_section_1
putserv "TOPIC $chan :$t_start $t_colour $topic_section_1 $t_end"
close $fileid
 } elseif {$topic_sections == "2"} {
set fileid [open tristam-topic_1.txt r]
gets $fileid topic_section_1
close $fileid
set fileid [open tristam-topic_2.txt r]
gets $fileid topic_section_2
putserv "TOPIC $chan :$t_start $t_colour $topic_section_1 $t_middle $t_colour $topic_section_2 $t_end"
close $fileid
 } elseif {$topic_sections == "3"} {
set fileid [open tristam-topic_1.txt r]
gets $fileid topic_section_1
close $fileid
set fileid [open tristam-topic_2.txt r]
gets $fileid topic_section_2
close $fileid
set fileid [open tristam-topic_3.txt r]
gets $fileid topic_section_3
putserv "TOPIC $chan :$t_start $t_colour $topic_section_1 $t_middle $t_colour $topic_section_2 $t_middle $t_colour $topic_section_3 $t_end"
close $fileid
 } elseif {$topic_sections == "4"} {
set fileid [open tristam-topic_1.txt r]
gets $fileid topic_section_1
close $fileid
set fileid [open tristam-topic_2.txt r]
gets $fileid topic_section_2
close $fileid
set fileid [open tristam-topic_3.txt r]
gets $fileid topic_section_3
close $fileid
set fileid [open tristam-topic_4.txt r]
gets $fileid topic_section_4
putserv "TOPIC $chan :$t_start $t_colour $topic_section_1 $t_middle $t_colour $topic_section_2 $t_middle $t_colour $topic_section_3 $t_middle $t_colour $topic_section_4 $t_end"
close $fileid
 } elseif {$topic_sections == "5"} {
set fileid [open tristam-topic_1.txt r]
gets $fileid topic_section_1
close $fileid
set fileid [open tristam-topic_2.txt r]
gets $fileid topic_section_2
close $fileid
set fileid [open tristam-topic_3.txt r]
gets $fileid topic_section_3
close $fileid
set fileid [open tristam-topic_4.txt r]
gets $fileid topic_section_4
close $fileid
set fileid [open tristam-topic_5.txt r]
gets $fileid topic_section_5
putserv "TOPIC $chan :$t_start $t_colour $topic_section_1 $t_middle $t_colour $topic_section_2 $t_middle $t_colour $topic_section_3 $t_middle $t_colour $topic_section_4 $t_middle $t_colour $topic_section_5 $t_end"
close $fileid
 } else {
puthelp "PRIVMSG $chan :ERROR :P"
 } }
Tristam - tristam@iki.fi
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Instead of a lot ifs and elses use the switch command.
Once the game is over, the king and the pawn go back in the same box.
User avatar
TALES
Halfop
Posts: 59
Joined: Sun Nov 09, 2003 8:45 am
Location: Netherlands
Contact:

Post by TALES »

could be something like this ??

example:

Code: Select all

if {$topic_sections == "0"} { 
puthelp "PRIVMSG $chan :There is no topic set in $chan!" 
 } elseif {$topic_sections == "1"} {
  #your code
  set topic_sections "2"
 } elseif {$topic_sections == "2"} {
  #your code
  set topic_sections "1"
 } else {
  #your code
  set topic_section "1"
 }
}
User avatar
Tristam
Voice
Posts: 17
Joined: Sun Sep 21, 2003 11:28 am
Location: Finland

Post by Tristam »

Hmm...

No TALES, that's what I can do already. The problem is, when I use if's and elseif's, that it stops after making all the commands. And if I use one if or elseif to make commands, I cant use if or elseif in the commands again..

caesar, I tried to look for an "switch" command, here it is: http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm. The only problem is that I dont understand it :) Could you please help me out and make a _simple_ example of the usage? (I really dont understand how that command would help me with my problem..) ;)

help a noobi, thanks :>

EDIT:// I'll try to explain the problem again: First, I take a number from a text file, check it with if and elseif commands to set up few variables depending what's the number in the text file. After that, I want it to continue with a code, which gives different output depending which variables were set. I hope you understand it :)
Tristam - tristam@iki.fi
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

set number 1
switch -- $number {
  "1" {
    # do something with this number
  }
  "2" {
    # do something with this number
  }
  "3" {
    # do something with this number
  }
}
Once the game is over, the king and the pawn go back in the same box.
User avatar
Tristam
Voice
Posts: 17
Joined: Sun Sep 21, 2003 11:28 am
Location: Finland

Post by Tristam »

uuuuh now it all makes sense :) thanks a lot once again! :>
Tristam - tristam@iki.fi
Locked