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.

On join msg; doesn't work when users have no record in bot

Help for those learning Tcl or writing their own scripts.
Post Reply
r
rapattack
Voice
Posts: 6
Joined: Thu Aug 18, 2011 7:12 am

On join msg; doesn't work when users have no record in bot

Post by rapattack »

Dear all,

I was creating something that mentions which score a user has and also which rank he has got when he joins the trivia chan.

Below is the code:

Code: Select all

proc tgjoinmsg {nick host hand chan} {
	global botnick tgplaying tgcmdhelp tgcmdstart tgflagsstart tgcmdstop tgflagsstop tgchan tgscoresbyname tgranksbyname
	if {$nick != $botnick} {
		set _msg ""
		append _msg "Welcome $nick! You're on the [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])][tgcolmisc1] rank with [tgcolmisc2]$tgscoresbyname([strlwr $nick])[tgcolmisc1] points."
		if {$tgplaying==1} {
			append _msg ""
		} else {
			append _msg ""
		}
		if {[matchattr $hand $tgflagsstart $tgchan]&&$tgplaying==0} {
			append _msg "!!!Enter !start to start the game!!!"
		}
		append _msg ""
		[tgpriv] $chan "$_msg"
	}
}
It works when the user already has a score (1 or above), but it doesn't work for unknown users... I'd like the bot to say Welcome to the new user, and tell him that he currently doesn't have any scores.

Thanks for all help in advance !!!!!!! :-)


Oh yeah this is the error I get when an unknown user joins the channel:
[13:09:20] Tcl error [tgjoinmsg]: can't read "tgranksbyname(maagd15m)": no such element in array

But I don't know how to fix it :) Thanks!
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Trivia with a working onjoin message:)

Post by SpiKe^^ »

Try BogusTrivia for a trivia game with a working on join message for unknown players.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: On join msg; doesn't work when users have no record in b

Post by speechles »

rapattack wrote:It works when the user already has a score (1 or above), but it doesn't work for unknown users... I'd like the bot to say Welcome to the new user, and tell him that he currently doesn't have any scores.

Code: Select all

proc tgjoinmsg {nick host hand chan} {
	global tgscoresbyname tgranksbyname tgflagsstart tgplaying tgchan
	# is it the trivia channel?
	if {![string equal $chan $tgchan]} { return }
	# yes, is it the bots nickname?
	if {![botnick $nick]} {
		# no, does an entry exist for this nickname?
		if {[info exists tgranksbyname([strlwr $nick])]} {
			# yes, set the message
			set _msg "Welcome $nick! You're on the [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])][tgcolmisc1] rank with [tgcolmisc2]$tgscoresbyname([strlwr $nick])[tgcolmisc1] points."
			# is trivia off, but this person can start it?
			if {[matchattr $hand $tgflagsstart $tgchan]&&$tgplaying==0} {
				# yes, append the message
				append _msg " !!!Enter !start to start the game!!!"
			}
		} else {
			# no, an entry doesn't exist for this person, set the message
			set _msg "Welcome $nick. You currently have no score for trivia."
		}
		# output
		tgpriv $chan "$_msg"
	}
}
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Why not call only the tgchan variable and if the channel is it the trivia channel proceed with also calling the rest of the variables? In theory should save up precious some resources.

Also, why not store nick in a lower format (strlwr $nick) and use it instead of transforming it 3 times.
Once the game is over, the king and the pawn go back in the same box.
p
pektek
Halfop
Posts: 41
Joined: Sat Jul 01, 2023 4:51 pm

Re: On join msg; doesn't work when users have no record in bot

Post by pektek »

Code: Select all

proc tgjoinmsg {nick host hand chan} {
	global tgscoresbyname tgranksbyname tgflagsstart tgplaying tgchan
	# is it the trivia channel?
	if {![string equal $chan $tgchan]} { return }
	# yes, is it the bots nickname?
	if {![botnick $nick]} {
		# no, does an entry exist for this nickname?
		if {[info exists tgranksbyname([strlwr $nick])]} {
			# yes, set the message
			set _msg "Welcome $nick! You're on the [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])][tgcolmisc1] rank with [tgcolmisc2]$tgscoresbyname([strlwr $nick])[tgcolmisc1] points."
			# is trivia off, but this person can start it?
			if {[matchattr $hand $tgflagsstart $tgchan]&&$tgplaying==0} {
				# yes, append the message
				append _msg " !!!Enter !start to start the game!!!"
			}
		} else {
			# no, an entry doesn't exist for this person, set the message
			set _msg "Welcome $nick. You currently have no score for trivia."
		}
		# output
		tgpriv $chan "$_msg"
	}
}
this shape change

Code: Select all

#triggered when someone joins trivia chan. 

proc tgjoinmsg {nick host hand chan} {
	global botnick tgscoresbyname tgranksbyname tgflagsstart tgplaying tgchan
	# is it the trivia channel?
	if {![string equal $chan $tgchan]} { return }
	# yes, is it the bots nickname?
	if {$nick != $botnick} {
		# no, does an entry exist for this nickname?
		if {[info exists tgranksbyname([strlwr $nick])]} {
			# yes, set the message
			set _msg "Welcome $nick! You're on the [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])][tgcolmisc1] rank with [tgcolmisc2]$tgscoresbyname([strlwr $nick])[tgcolmisc1] points."
			# is trivia off, but this person can start it?
			if {[matchattr $hand $tgflagsstart $tgchan]&&$tgplaying==0} {
				# yes, append the message
				append _msg " !!!Enter !start to start the game!!!"
			}
		} else {
			# no, an entry doesn't exist for this person, set the message
			set _msg "Welcome $nick. You currently have no score for trivia."
		}
		# output
		[tgpriv] $nick "$_msg"
	}
}

Post Reply