Capturing a word from World

Posted by Solara on Mon 04 Jun 2012 07:16 PM — 8 posts, 27,195 views.

USA #0
Hello, I'm trying to create a script to grab a password after I execute a spell. Then I need to whisper that password to the face to open a door.

Two problems:
1- when I capture the password and capture it as a variable, there's a leading space in front of it which the door wont' accept. How do I truncate the first empty space?
2- I can't seem to do a Send command (using Lua) with additional text along with the variable. I'm sure it's syntax, but if I can't do a Send command with additonal text combined with the variable, how do I combine two variables together into one string?

Trigger: The runes have moved to form the word:*
Code:
require "wait"
wait.make (function ()

SetVariable ("password", "%1")
SetVariable ("password", (string.format ("%.9s", (GetVariable ("password")))))
Note (GetVariable ("password"))
Send ("rub orb")
wait.time (06)
Send ("whisper face Your name is" (GetVariable ("password")))

end)

The %.9s truncates the last letter, but I'm trying to truncate the first letter.
And I get an script error for the Send ("whisper... line.

Thanks for any help!
USA #1
Ok after reading another thread, I fixed the first problem. Still can't do a Send command with new preceding text along with the variable. Here's the revised code so far:

require "wait"
wait.make (function ()

SetVariable ("password", (string.sub ("%1", 2, 10)))
Send ("rub orb")
Note (GetVariable ("password"))
wait.time (06)
Send ("whisper face Your name is (GetVariable ("password")))

end)
USA #2
Okay so I figured out the answer to both problems. BUT I've run into a new problem. Here's the trigger script:

require "wait"
wait.make (function ()

SetVariable ("password", (string.sub ("%1", 2, 10)))
Send ("rub orb")
Note (GetVariable ("password"))
wait.time (06)
Send ("whisper face Your name is @password")
Send ("s")
Send ("close door")

end)

So what happens when I run is it that it will correctly Note the current password. But for some bizarre reason it's sending the previous password instead! It appears the password variable gets changed and is noted correctly, but then when you do @password, it uses the previously stored one? Anyone know what's going on here?
USA #3
Well I worked around the problem by creating two triggers.
First trigger sets the variable.
Second trigger whispers the password.

Seems the @password is set at the onset of the trigger, and does not get updated while the script is running - though the variable itself is changed and is displayed correctly with the 'Note' command. But for some odd reason the 'Send @password' sends the previous password.
USA Global Moderator #4
GetVariable(foo) and @foo do not do the same thing. As you noted, the @ syntax is just a preprocessor that substitutes values at entrance. GetVariable does what you want.
Amended on Tue 05 Jun 2012 12:00 AM by Fiendish
USA #5
How can I use the Send command to send some text along with the GetVariable then? I've found a workaround but it would be more elegant to have it in one trigger instead of two.

This does not work. I get a script error:

Send ("whisper face Your name is (GetVariable ("password")))
Amended on Tue 05 Jun 2012 12:40 AM by Solara
USA Global Moderator #6
Try

Send("whisper face Your name is "..GetVariable("password"))
USA #7
Thanks Fiendish, that did the trick.