PDA

View Full Version : Help with toggle_unique



Yasutoshi
05-16-2014, 10:51 AM
I'm working on a multi-threaded script and one of the threads listens for:

;send to 'scriptname' report

When it receives the report unique data it then spits out a report.

The script also hunts and does other things. However, I've been receiving a:

"this script is set as unique but is waiting for game data" message with a 2 second delay. I even see where it's listed in lich.

I want to be able to receive both game data and unique data.



toggle_unique
clear
def reporting
loop {
msg = unique_get.strip
if msg == 'report'
monster_report
end
}
end
talker = Thread.new{ reporting }
talker.join


The above is a section of the script. So other sections of the script where I do:

fput "stance defensive" or any type of matchwait receives the script is set as unique.... followed by a 2 second delay.

The end goal is to be able to do both. There's very little documentation with lich, even in the Lich Scripting Reference.

Help would be appreciated.

Yasutoshi
05-16-2014, 11:05 AM
I think I figured it out. I didn't realize there was another "get" versus "unique_get". So I removed toggle_unique and replaced msg = unique_get.strip to msg = get.strip

Yasutoshi
05-16-2014, 11:18 AM
It looks like I'll need to use toggle_unique but will have to call it again to change it to false and again to back to true (before and after) I need to use game_data. If I use the normal get method it will hose the entire script.

Yasutoshi
05-16-2014, 11:39 AM
Verified and I was correct. I definitely need to use toggle_unique and unique_get.

For commands like fput... or any command that is game data, I have to wrap it with:

toggle_unique
fput "stance defensive"
toggle_unique

Which is the same as saying:

false
fput "stance defensive"
true

Disabling and re-enabling the unique flag.

Tillmen
05-16-2014, 01:26 PM
toggle_unique has a misleading name. It actually just turns the game stream on or off for the script. It doesn't turn the unique stream on or off. The command is only there for backwards compatibility. I prefer to use script.want_downstream = true/false.

For your script, don't use toggle_unique at all. This will give you a normal downstream buffer that you access with get, and a unique buffer you access with unique_get. The problem this creates is that when you use ;send, it will be sending to the downstream buffer, because it only sends to the unique buffer if the downstream buffer is disabled. That's OK though, because you can send to the unique buffer with another method.
Here's a couple options:

;alias add ;usend=;eq args = "\?"; args.sub!(/^to /, ''); sn = args.slice!(/^.+?\s/).chop; unique_send_to_script(sn, args)
Then use ;usend as you were using ;send

or

;alias add ;report=;eq unique_send_to_script('scriptname', 'report')
Then just type ;report

Yasutoshi
05-17-2014, 09:49 AM
Thanks for the explanation mate. I appreciate the answer and the optional solutions.

Yasutoshi
05-17-2014, 10:19 AM
The simplest solution I felt was implementing a quick talker script so that people don't need to create aliases. It just includes one line that coordinates with the main script:

#;askmonk
unique_send_to_script(myscriptname, variable[1])

and that just allows them to create a macro for: ;askmonk report OR ;askmonk timer OR ;askmonk help

And, this is much cleaner so I appreciate it!