[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Struggling.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Struggling.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by Siris   (17 posts)  [Biography] bio
Date Fri 27 Aug 2010 10:35 PM (UTC)

Amended on Fri 27 Aug 2010 10:39 PM (UTC) by Siris

Message
I'm struggling with grasping LUA's language, I'm trying to set up some direction aliases and cannot for the life of me get it to work.

<aliases>
<alias
match="ne"
enabled="y"
send_to="10"
keep_evaluating="y"
sequence="100"
>
<send>if fighting = 1 then
send "flee northeast"
else
send "northeast"
end</send>
</alias>
</aliases>


I've scripted extensively in zmud and I want a more powerful {and free} Client. However I can not figure out what I'm doing wrong. This is the error I get:

Compile error
World: Moongate
Immediate execution
[string "Immediate"]:1: 'then' expected near '='
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Fri 27 Aug 2010 10:42 PM (UTC)
Message
You want to use ==, not =. Single-equals is for assignment (i.e. storing a value in a variable). Double-equals is for comparison. :)

Also, you need to use Send("flee northeast"). Case is extremely important, "send" refers to a different value than "Send".

You also have a syntax error in the else branch:

send, "northeast"


Commas never go between the function and its arguments, only between the arguments themselves. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 27 Aug 2010 10:43 PM (UTC)
Message
There is a fantastic online book about Lua, written by the developer:

http://www.lua.org/pil/

In your case you have two problems. Unlike what you may be used to in zMud (and Visual Basic) to test for "equals" you have to use ==.

Thus:


if fighting == 1 then


A single "=" is used to assign. For example:


a = 2    -- assign
if a == 2 then   -- test
  print ("a is two!")
end


Also, the internal functions are case-sensitive, it is Send, not send.

Use the "Complete" button in the editor to complete a function name, which also corrects the capitalization.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 27 Aug 2010 10:44 PM (UTC)
Message
Ninja'd! And I didn't spot the comma.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Siris   (17 posts)  [Biography] bio
Date Reply #4 on Fri 27 Aug 2010 10:54 PM (UTC)
Message
lol, i proof read it again and tried to fix my syntax errors, i'm not new to scripting just new to lua. ;) thank you for your fast response guys.
[Go to top] top

Posted by Siris   (17 posts)  [Biography] bio
Date Reply #5 on Fri 27 Aug 2010 11:01 PM (UTC)
Message
<variables>
<variable name="fighting">1</variable>
</variables>

<aliases>
<alias
match="ne"
enabled="y"
send_to="12"
keep_evaluating="y"
sequence="100"
>
<send>if fighting == 1 then
Send ("flee northeast")
else
Send ("northeast")
end</send>
</alias>
</aliases>

Errors are done with, however it will not send flee northeast to the mud. I hate to seem like such a newbcake, but I fail to see what I'm missing
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #6 on Fri 27 Aug 2010 11:16 PM (UTC)
Message
Ah, because there are two kinds of variables: MUSHclient variables, and the scripting language's native variables. MUSHclient variables are held by MUSHclent, and you're using one by using <variable>. On the other hand, scripting variables (in this case, Lua's variables) are native language constructs, which you're attempting to use in your if-statement.

Change fighting in the if-statement to GetVariable("fighting"). Also, because MUSHclient variables can only contain strings, you need to check it against "1" instead of 1.

That's probably the most common trip-up when you're dealing with MUSHclient. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 27 Aug 2010 11:19 PM (UTC)
Message
Yeah. The other question is how does "fighting" get set in the first place?

It could be easier to set the Lua variable rather than the MUSHclient variable.

eg.


<triggers>
  <trigger
   enabled="y"
   match="* kicks you!"
   send_to="12"
   sequence="100"
  >
  <send>fighting = 1</send>
  </trigger>
</triggers>


Now that trigger sets the Lua variable rather than the MUSHclient variable, and then your alias works as is.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Siris   (17 posts)  [Biography] bio
Date Reply #8 on Fri 27 Aug 2010 11:23 PM (UTC)

Amended on Fri 27 Aug 2010 11:33 PM (UTC) by Nick Gammon

Message
Thank you again. I will read the manual, and hopefully stop pestering you fine gentlemen. One last question though. Nick Your gui mapper seems to only use one line exit codes do you think it could be adapted to read multiple line exit codes? My mud's room code is as follows:


 Mayor's Office                                         -      -      -
(-------------------------------------------------)     - <---(M)-D-> -
                                                        -      S      -

  The office of Lord Telleri is luxurious enough to impress visitors with
the importance of the occupant, but still has all the markings of a working
office.  Despite the best efforts of secretaries and assistants, papers are
stacked on every corner of the priceless hand-carved desk, and half-read
briefs litter the credenza.  
*[Quest] Lord Telleri stands before you with a slight grin on his face.


and unfortunately some room descriptions are identical, however could that be manually mapped when the rooms are identical?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Sat 28 Aug 2010 12:32 AM (UTC)
Message
The GUI mapper really comes in two parts. The "core" mapper is a Lua module (mapper.lua) which comes with MUSHclient. This will draw a GUI map based on whatever information gets fed into it.

There are a couple of implementations of mapper plugins (one is the ATCP_Mapper.xml). I also did a "simple" one which doesn't use the telnet codes that the ATCP mapper does. This is presented here:

http://www.gammon.com.au/forum/bbshowpost.php?id=10138&page=7

As described in that thread, the core problem is to recognize rooms uniquely. If they happen to give you room numbers, that's great! Otherwise I hashed up the room description (and the exits I think) to give something that hopefully is unique.

In your case you might be able to adapt the simpler mapper to hash up the lines you showed (Mayor's Office, exits, description) to give something unique.

The exits themselves aren't that critical, as I think the plugin recognized when you typed a direction (eg. East) and when you entered a new room (because of the hash) and therefore it knows that east from room x takes you to room y.

There might be a way of handling absolutely identical room descriptions (assuming the exits are also identical) by remembering which room led to this one.

For example room a (reached from b) could be different from room a1 (reached from c) even if a and a1 had the same descriptions (because you remember how you got there).


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #10 on Sat 28 Aug 2010 01:07 AM (UTC)
Message
Twisol said:

...
Also, you need to use Send("flee northeast").

...


To be perfectly accurate, in Lua when passing a single string literal or single table construct to a function, the parentheses are optional.


print "Hello world."

require "tprint"
tprint { 1,2,3 }


print("Hello world.")
require("tprint")
tprint( {1,2,3} )


are equivalent.

So his original

send "flee northeast"

only needed the capitalization fixed.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #11 on Sat 28 Aug 2010 01:17 AM (UTC)
Message
WillFa said:
To be perfectly accurate, in Lua when passing a single string literal or single table construct to a function, the parentheses are optional.

It's an exceptional case grandfathered in from Lua's roots, and it only works when you have just one argument (which must be a string literal or a table literal). I'd rather teach people the way that always works first. =/


'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Siris   (17 posts)  [Biography] bio
Date Reply #12 on Sat 28 Aug 2010 03:12 AM (UTC)
Message
thank you guys, got everthing working. hopefully i woulnt be bugging you guys for simplistic problems everyday.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #13 on Sat 28 Aug 2010 03:13 AM (UTC)
Message
Well, don't be too afraid to ask again. :) I helped a lot of really new users every day in the MUSHclient clan on Achaea, and it makes me happy to see someone learn the ropes and begin doing interesting things.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #14 on Sat 28 Aug 2010 03:14 AM (UTC)

Amended on Sat 28 Aug 2010 03:20 AM (UTC) by WillFa

Message
Twisol said:

WillFa said:
To be perfectly accurate, in Lua when passing a single string literal or single table construct to a function, the parentheses are optional.

It's an exceptional case grandfathered in from Lua's roots, and it only works when you have just one argument (which must be a string literal or a table literal). I'd rather teach people the way that always works first. =/




That's what I said...

I don't agree with your insinuation that it's "grandfathered". It was a deliberate choice and I've never read anything suggesting that if they had the choice to make all over again, they wouldn't make the same one. I don't think it's so exceptional when 95% of all Lua code I've read or written starts with it. (require "foo")

You're fixing mistakes that aren't mistakes. He didn't 'need to use Send()'. He needed a capital S. Don't teach that Send "flee northeast" is wrong, because it's not, and it will confuse your student when they do try to figure out why something like require "foo" works. (Is require a keyword? Nope, it's just a function included by default. But I was taught that functions need parentheses...)





http://xkcd.com/386/
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


8,897 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]