mIRC Home    About    Download    Register    News    Help

Print Thread
#117324 14/04/05 05:21 PM
Joined: Feb 2005
Posts: 9
K
Kaepez Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Feb 2005
Posts: 9
I'm currently collaborating on a script with someone, and we've encountered a small problem.

We have a main script, which, when run, will ask for a few words.

I need the script to then record the words submitted by a user into a few variables, say, %word1 %word2 and %word3.

The best way I can think of doing so is using a separate on TEXT command, which will record the word submitted after a keyword. For simplicity, I'll say the keyword is !submit.

In other words, I want the script to say, "Give me your name." The script will then activate the on TEXT remote, (through either /enable or an if statement, it doesn't matter to me), the on TEXT will record the name said after "!submit NAME," and the script will go on to ask for other words.

I can get this to work, except for the fact that I am unaware of how to get the original script to wait until the on TEXT script has recorded a value into %word1.

Excuse me if this is worded awkwardly; I can't think of any better way to put it at the moment.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Here's a basic script for you to play with:

on *:text:!start:#chan: {
msg $nick What is your name?
set $+(%name,.,$nick,.position) 1
}

on *:text:*:?: {
if ($+(%name,.,$nick,.position) == 1) {
set $+(%name,.,$nick,.name) $1-
inc $+(%name,.,$nick,.position)
msg $nick What is your age?
}
elseif ($+(%name,.,$nick,.position) == 2) {
set $+(%name,.,$nick,.age) $1-
inc $+(%name,.,$nick,.position)
msg $nick Where do you live?
}
****CONTINUE AS NEEDED****
}

How this works:

* In the channel, someone starts the questionaire script with !start.

* The script msgs them with the question for what their name is.

* They reply through query with just their name (no triggers needed)

* The script then asks the next question and so on... just add more sections to get all the answers.

Because of how the variables are handled, it will only ask the correct question to the correct person. 20 people can be answering questions at the same time and it wouldn't be a problem. And a person can answer whenever they want ... even days later as long as you don't reset the variables.

Note that depending how you're starting the script, you may not need the first on text command. Also, if you don't want people to answer in a query window (private message), then you can change the second on text to #chan or whatever you want rather than "?".

You may want to change the variables for where the nick/age/etc are stored depending how where you need them for the rest of your script. For example, you may want them put into a text or ini file or a hash table or variables of some other name or whatever. Just change them as needed.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias mainscript {
  if ($1 == goto) { goto $2 }
  ;
  ;normal start of code here
  ;
  do what ya wanna do here BUT you MUST save any $1- values and anything else you well need to global variables NOW!
  ;
  set %ontext.matchtext !name *
  set %ontext.matchnick [color:purple]<nick to enter it>[/color]
  set %ontext.resumemark [color:blue]marker1[/color] 
  enable #submitvalue
  msg $chan Give me your name | return
  :[color:blue]marker1[/color] 
  disable #submitvalue
  set %name [color:orange]$4-[/color]
  ;
  ; more stuff you do here
  ;
  set %ontext.matchtext !sex *
  set %ontext.matchnick [color:purple]$nick[/color]
  set %ontext.resumemark [color:red]aftersex[/color] 
  enable #submitvalue
  msg $chan Give me your name | return
  :[color:red]aftersex[/color] 
  disable #submitvalue
  set %sex [color:orange]$4-[/color]
  ;
  ; more stuff you do here
  ;
  repeat as per second example , see notes on [color:purple]$nick[/color]
  etc etc
}
;
#submitvalue off
on *:TEXT:%ontext.matchtext:*:{ if ($nick == %ontext.matchnick) { mainscript goto %ontext.resumemark $1- } }
#submitvalue end


marker1 & aftersex are the goto marks in your program where you would like to carry on from after the input from the user.
<nick to enter it> this is the nick you want to answer
$nick the second time the $nick value happens to have the nicks name in it. (you can use this or pull it from elsewhere if u want)
$4- in both examples here its $4- becuase it was
(1) $1- = goto marker1 !name DaveC
(2) $1- = goto aftersex !sex Male

Just remebr you have to use global sets becuase your really calling the routine over and over, so VAR are all lost.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The only problem with using triggers is that you have to tell people what to use as a trigger for it to work.

Example: "What is your name? (use !Name yourname)"

That is why I suggested doing it without triggers. laugh


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2005
Posts: 9
K
Kaepez Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Feb 2005
Posts: 9
Thanks for your help! I got it working the way I wanted to. I ended up using DaveC's method, mainly because the rest of my script was already centered around triggers.

Once again, thanks.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Its easy just tell them, like you said, or as he originally said, just use one trigger !submit i think it was, either way that works, I didnt design it to work for multiple people, i didnt think he asked for it, might have been wrong, its only a slight change to make it multi user, or channel or network even

PS: one thing i dont understand in yours is whats the contents of %name ? you never defined it, which certianly wasnt going to be a help to him.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The values are indeed set.

Example:

I type !start, so...

%name.Riamus2.position starts out at 1 (eg. ask question #1 to Riamus2)

%name.Riamus2.name sets to my name when I reply with my name in the query window and the position increases to 2 (eg. ask question #2)

%name.Riamus2.age sets to my age when I reply with my age... etc.

And, as I said, you can use other methods to store the information depending how the rest of the script needs it... saving in an ini for example.

The use of this is that it automatically works for everyone and can easily be stored in any way you want to with only a small change. The main reason I did it this way was to prevent the need for using triggers constantly. The bot asks you "What is your name?" and you simply reply with your name.

I'm not saying that yours doesn't work because it will. Just explaining mine since you asked.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
The values are indeed set.


lol, they would have been if you did them right

set $+(%name,.,$nick,.position) 1
%name is evaluated and if %name holds no value then you end up with...
set .DaveC.position 1

%name needed to be %,name

also the below (even inserting the correction to the above)
if ($+(%,name.,$nick,.position) == 1) {
becomes
if ($+(%,name.,DaveC,.position) == 1) {
becomes
if (%name.DaveC.position == 1) {
and since the string litteral "%name.DaveC.position" doesnt == 1 it wont occur

$+(%,name.,$nick,.position) needed to be $($+(%,name.,$nick,.position),2) or [ [ $+(%,name.,$nick,.position) ] ]


Only problem i have with using no triggers is most people well chatter in a channel even when being asked info, so I would feel its important that the user be able to specify whats there question reply and what isnt.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ah, you are correct. I missed that comma.

As far as your comment about triggers, if it is being done in a channel, then I agree. I would not think asking these questions would be done within a channel, however. Unless everyone wants their information seen by the entire channel, you probably would enter this through a query (private message). Perhaps not as I don't know what all he is asking or who is in the channel. Just thinking that personal information usually isn't something someone will enter in a channel anyhow. That's why I set it to receive text through private message rather than the channel.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard