|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Wed Jan 14, 2009 7:55 pm
Having problems with Lua and Cmud |
I'm not sure what is going on. I've found a few bugs in the last couple of days. The syntax highlighting one is really giving me a headache. However, now I am discovering other issues.
For example, I made my own substitute function instead of having to zs.substitute("blah blah") I just do sub("blah). I restart Cmud and it all works fine. I test a trigger and it subs great. I run another function it works fine. I test the trigger again and suddenly it doesn't sub anymore or even fire for that matter.
Example:
Cured: Weakness
=========
AFFLICTIONS
=========
Your limbs strengthen and you feel stronger.
That's directly from the screen.
The first line substituted correctly. I then ran the check afflictions function and then did a show to see if it would sub and it failed.
checkaffs function
Code: |
function checkaffs()
zs.print("<color red>=============</color>")
zs.print("<strong><color 'red'>AFFLICTIONS</color></strong>")
zs.print("<color red>=============</color>")
for affliction, v in pairs(afflicted) do
if afflicted[affliction] then
zs.print("<color white>" .. affliction .. "</color>")
end
end
end |
What exactly in that would cause sub to break?
I load all my LUA in an onLoad event.
I'm having nothing but problems... |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 15, 2009 6:27 am |
Where's the zs.sub() in your example?
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Jan 15, 2009 8:28 am |
Code: |
<trigger name="curedWeakness" priority="12410" case="true" regex="true" language="Lua" id="449">
<pattern>^Your limbs strengthen and you feel stronger\.$</pattern>
<value><![CDATA[sub("<color lime>Cured:</color><color khaki> Weakness</color>")
unafflict("weakness")]]></value>
</trigger> |
Code: |
function sub(arg)
zs.substitute(arg)
end
|
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sat Jan 17, 2009 8:25 pm |
Can you not execute an LUA function from an alias? Every time I do it stops all my functions from working.
Example an alias restaffs which executes function resetaffs().
Afflicted: Asthma
Afflicted: Asthma <-- Lua works
Afflictions cleared <-- alias and function ran here
You feel a tightening sensation grow in your lungs. <-- LUA no longer works
You feel a tightening sensation grow in your lungs. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jan 18, 2009 5:07 am |
I give up. This is pointless and I have no idea why it is happening. Simply looping through a table should not stop stuff like zs.sub etc. from working.
Edit:
If I use LUA command line it doesn't break. Otherwise if I enter the alias on the normal command line it breaks LUA and zs.sub() and the rest stop working.
Entering affliction line with SHOW...
Afflicted: Anorexia
Calling function to loop through affliction table from command line...
=========
AFFLICTIONS
=========
*anorexia*
Entering affliction line again using SHOW...
Afflicted: Anorexia
Now calling function to loop through affliction table with alias...
=========
AFFLICTIONS
=========
*anorexia*
Once again entering affliction line with SHOW...
Afflicted: Anorexia
OK this was all using the LUA command line.
Now switching to Zscript command line
Entering affliction line again..
Afflicted: Anorexia
Now executing alias from command line.
=========
AFFLICTIONS
=========
*anorexia*
Now going to try affliction line again...
The idea of eating or drinking is repulsive to you.
The idea of eating or drinking is repulsive to you.
The idea of eating or drinking is repulsive to you.
The idea of eating or drinking is repulsive to you.
The idea of eating or drinking is repulsive to you.
Broken..
Does this mean you always have to use the LUA command line after you load LUA scripts? |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jan 18, 2009 5:55 am |
I can't believe none of you have problems. ANY time I enter alias on command line that contains any LUA code at all it breaks it. If the alias has zscript then LUA continues working.
So apparently you can't put LUA code into an alias?? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jan 18, 2009 6:08 am |
No, you can, and nobody else has ever reported this kind of issue - which makes me think it's some kind of systemic problem with your setup. If you've fully reinstalled CMUD (including deleting the folder first) and then tried creating some of the same things in a brand new package, though, I'm not sure what to suggest.
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jan 18, 2009 6:25 am |
Yes I did reinstall, and I reinstalled after deleting the folder too.
It comes down to this. Calling a function from an alias will cause zs.* anything to stop working.
Example, I have an oninput trigger where I capture zs.param(1) into a local variable to use in a script. After I ran the "affs" alias from the command line which does nothing but simply execute checkaffs() which does nothing but simply loop through the afflictions table and checks to see if any are true, then zs.whatever will no longer work period. zs.param(1) ends up being 0 even when it should have captured %1. That means my scripts stop working. Substitutes stop working and so on. I changed the zs.param(1) to a string that matches for the code and the code executed fine. When I restart Cmud it starts working again.
It is a problem with zs.* and I am not sure why it stops working simply from executing a function from an alias. Executing the very same exact function on the LUA command line didn't cause it to stop working. Executing the alias which executes the function from the zscript command line causes it to stop working.
Edit: Actually zs.print() still works...just zs.param() stops working and zs.sub() stops working. Not sure what else. Guess I can looking through all of them. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jan 18, 2009 6:58 am |
Fang, I created just those 3 settings in a brand new pack and empty session and the same thing happens.
I put the afflicted table and checkaffs() function into an onLoad event. I created an alias to call checkaffs(). Then I created a trigger line that would substititue the line with zs.sub etc if it contained a valid word and also set that value to true in the afflicted table.
I then used SHOW and it subbed the trigger fine. I then ran affs and it executed the function checkaffs and printed the output. However, I then used SHOW again to see if it would sub and once again zs.param() and zs.sub() stopped working.
Output:
Afflicted: Anorexia
Afflicted: Anorexia
Afflicted: Anorexia
Afflicted: Anorexia
Afflicted: Anorexia
=============
AFFLICTIONS
=============
anorexia
You are afflicted with anorexia.
Not a valid affliction.
zs.param() is 0
You are afflicted with anorexia.
Not a valid affliction.
zs.param() is 0
Here is the code so you can try it:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<class name="Test" copy="yes">
<event event="onLoad" priority="10" copy="yes">
<value><![CDATA[print("Loading LUA...")
afflicted = {
addiction = false,
aeon = false,
agoraphobia = false,
anorexia = false,
asthma = false,
blackout = false,
bound = false,
brokenLeg = false,
brokenArm = false,
burning = false,
claustrophobia = false,
clumsiness = false,
cold = false,
confusion = false,
darkshade = false,
deadening = false,
dementia = false,
disloyalty = false,
dissonance = false,
dizziness = false,
epilepsy = false,
generosity = false,
haemophilia = false,
hallucinations = false,
headMangled = false,
healthleech = false,
heartseed = false,
hellsight = false,
hypersomnia = false,
hypochondria = false,
impaled = false,
impatience = false,
itching = false,
justice = false,
leftArm = false,
leftLeg = false,
leftArmMangled = false,
leftLegMangled = false,
lethargy = false,
loneliness = false,
lovers = false,
lusted = false,
madness = false,
manaleech = false,
masochism = false,
nausea = false,
pacifism = false,
paralysis = false,
paranoia = false,
prone = false,
recklessness = false,
rightArm = false,
rightLeg = false,
rightArmMangled = false,
rightLegMangled = false,
roped = false,
scytherus = false,
sensitivity = false,
shyness = false,
sleep = false,
slickness = false,
soulmaster = false,
spiritbond = false,
stupidity = false,
stunned = false,
stuttering = false,
throatLacerated = false,
throatSlashed = false,
torsoMangled = false,
transfixed = false,
vertigo = false,
voyria = false,
weakness = false,
webbed = false,
}
function checkaffs()
zs.print("<color red>=============</color>")
zs.print("<strong><color 'red'>AFFLICTIONS</color></strong>")
zs.print("<color red>=============</color>")
for affliction, v in pairs(afflicted) do
if afflicted[affliction] then
zs.print("<color white>" .. affliction .. "</color>")
end
end
end -- checkaffs function
]]></value>
</event>
<trigger priority="20" regex="true" copy="yes">
<pattern>^You are afflicted with (\w+)\.$</pattern>
<value>local a = zs.param(1)
if a == "anorexia" then
zs.sub("Afflicted: Anorexia")
afflicted.anorexia = true
else
zs.print("Not a valid affliction.")
zs.print("zs.param() is " .. a)
end </value>
</trigger>
<alias name="affs" copy="yes">
<value>checkaffs()</value>
</alias>
</class>
</cmud>
|
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jan 18, 2009 3:44 pm |
Well I was hoping someone had an answer while its the weekend and I can mess around with stuff more.
It is something to do with the zscript command line and running an alias from it that contains an LUA function. I've reinstalled. I've put three items into a brand spanking new empty session and it does the same thing so it isn't my package.
Like I said if I run this stuff from the LUA command line everything works just lovely. As soon as I run an alias with a function from zscript it just breaks.
Sorry to be complaining but I guess I will just go do something else. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jan 18, 2009 8:21 pm |
Is there a way to see if zs.sub and zs.param etc are disabled internally? This is really getting on my nerves.
|
|
|
|
chris-74269 Magician
Joined: 23 Nov 2004 Posts: 364
|
Posted: Sun Jan 18, 2009 11:12 pm |
I've seen problems with Leto's Hashset function where if you manually set the parameters from the commandline any calls to it from the script will not work, the nparams will cease to be populated and you get the "at least 3 arguments" error
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Jan 19, 2009 9:24 am |
Oldguy2 there is definitely a bug here. Apparently the trigger fails to capture the input parameters after the first time it successfully matched. So that's why you subsequent shows fail, it doesn't really have anything to do with the sub command being disable.
I've submitted a bug report to Zugg. |
|
_________________ Asati di tempari! |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Mon Jan 19, 2009 10:08 am |
Quote: |
Apparently the trigger fails to capture the input parameters after the first time it successfully matched. |
No Tech that is not the case. The main problem or cause of it is aliases with any LUA code in them being used, which in turn ceases the ability to capture input parameters or use substitute with LUA from ANY triggers. You can continue to use input parameters with aliases though and lua code.
For example, if I put the same exact function inside of a trigger or instead of using an alias use an oninput trigger to call an LUA function it continues working normally. However, as soon as I use the alias to call the lua function, then it will no longer capture the parameter and you can no longer substitute on ANY trigger.
Afflicted: Anorexia
Fired
Afflicted: Anorexia
Fired
Afflicted: Anorexia
Fired
Afflicted: Anorexia
Fired
Afflicted: Anorexia
Fired
Afflicted: Anorexia <-- still using input params and sub fine
Fired
Used an alias here with sendraw <--- Used an alias with lua code that uses sendraw so printed that output
The idea of eating or drinking is repulsive to you. <-- Now that I used the alias trigger no longer captures input params and sub broke
Fired
The idea of eating or drinking is repulsive to you.
Fired
The idea of eating or drinking is repulsive to you.
Fired
The idea of eating or drinking is repulsive to you.
Fired
The idea of eating or drinking is repulsive to you.
Fired
The idea of eating or drinking is repulsive to you.
Fired
Using an alias with zs.params() and print() below after it broke...
Entered alias TEST followed by the words NOT BROKEN
The params for this alias were not broken <-- continues to use input params just fine unlike triggers
Entered alias TEST followed by the words NOT BROKEN
The params for this alias were not broken
Entered alias TEST followed by the words NOT BROKEN
The params for this alias were not broken
I'm not understanding why using an alias containing LUA would cause all triggers to not be able to capture parameters or how it affects substitute.
As you can see, however, the trigger above continues capturing the input parameters after the first time it successfully matched though UNTIL I used an alias. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Jan 19, 2009 11:56 am |
Some simplified code for testing this
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="a" copy="yes">
<value>#LUA {pp()}</value>
</alias>
<alias name="b" copy="yes" language="lua">
<value>pp()</value>
</alias>
<alias name="setLua" copy="yes" language="lua">
<value>function pp()
for i=1,zs.numparam do print("param: "..i..":"..zs.param(i)) end
print("ext "..zs.param(1))
end</value>
</alias>
<trigger priority="40" copy="yes" language="lua">
<pattern>match:(%w) (%w) (%w)</pattern>
<value>print("fired")
pp()</value>
</trigger>
<trigger priority="50" copy="yes">
<pattern>match:(%w) (%w) (%w)</pattern>
<value>#SHOW fired2
#LOOP %numparam {#SHOW param:%i:%param(%i)}
#LUA {pp()}</value>
</trigger>
</cmud> |
Procedure:
1. Launch CMud
2. Close Sessions Window (ESC)
3. Open Package Editor (CTRL-G)
4. Paste the above into the tree panel of the PE
5. Enter at the command line
Code: |
setlua
#SHOW "match:a b c"
a a b c
b a b c
#SHOW "match:a b c" |
Sadly I, never installed 2.37. I don't actually see anything in the version history that indicate a change to how zs.param would behave from 2.36 though. My results are saying that captures from a trigger are never even made available to Lua. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Mon Jan 19, 2009 2:51 pm |
That's because you used an alias to load the function. Make it an oninput trigger and it will work fine UNTIL alias "a" runs.
Using alias to load function I get the result:
match:a b c
fired
ext 0 <-- already stopped working
fired2
param:1:a
param:2:b
param:3:c
ext 0
param: 1:a
param: 2:b
param: 3:c
ext a
param: 1:a
param: 2:b
param: 3:c
ext a
match:a b c
fired
ext 0
fired2
param:1:a
param:2:b
param:3:c
ext 0
Using an oninput trigger to load function I got:
match:a b c
fired
param: 1:a
param: 2:b
param: 3:c
ext a
fired2
param:1:a
param:2:b
param:3:c
param: 1:a
param: 2:b
param: 3:c
ext a
ext 0
param: 1:a
param: 2:b
param: 3:c
ext a
match:a b c
fired
ext 0
fired2
param:1:a
param:2:b
param:3:c
ext 0 |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Wed Jan 21, 2009 10:53 am |
I don't want to complain, but was this bug even looked at? I know you guys are working on the mapper, but I can't do much until it is fixed since every time I run an alias it basically stops most of my triggers from doing what they are supposed to do.
Thanks. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Wed Jan 21, 2009 3:19 pm |
Well the bug has been recreated by others, there are bug reports submitted and there are procedures to recreate it. So I think it's safe to say that Zugg is aware of this bug. I believe he's working on migrating and updating the current website (we should be on the new server already) then returning to work on the mapper.
As a work around you can try making the Lua portion a CMUD function then call that function using zScript. |
|
_________________ Asati di tempari! |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Wed Jan 21, 2009 5:42 pm |
Well I understand that but now I discovered that SEND doesn't execute oninput triggers from LUA either. I changed all my aliases to oninput triggers to get around this and ran into another wall already.
It was stated that LUA was fully supported. If knew all these problems existed, I wouldn't have bothered. I'm not sure why no one else found any of them yet and the help files are seriously lacking regarding LUA and getting it to work in CMUD.
It's like buttons. I can't use lua with them so I have to update my lua tables AND update a zscript variable, which is just kind of silly.
What is better? Should I not change the language to LUA in the value and just use half zscript and half with #LUA {}? |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Jan 21, 2009 5:44 pm |
Yes, these bugs are on the bug list.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Feb 04, 2009 9:59 pm |
Working on some of these Lua bugs today, but just wanted to point out something else:
zScript has had over 10 years of testing (in both zMUD and CMUD) and is used by over 70,000 customers. Lua support in CMUD has been available for only 2 years or so, and very few people have used it, so it has gotten a very small fraction of testing. The reason nobody else has found these problems is because very few people are using Lua in CMUD. It's usage is increasing as more people become familiar with Lua from other applications.
The help files actually have a huge amount of information regarding Lua compared to many other parts of CMUD (such as using other languages like VBScript).
In any case, have some patience. Using Lua in CMUD puts you on the cutting edge and there are bound to be problems. But as I said, I'm working on some of these bugs this week. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Feb 05, 2009 6:36 pm |
OK, I think I have this fixed in the next 3.04 version. Using Vijilante's simplified test, I get:
Code: |
#SHOW "match:a b c"
match:a b c
fired
param: 1:a
param: 2:b
param: 3:c
ext a
fired2
param:1:a
param:2:b
param:3:c
param: 1:a
param: 2:b
param: 3:c
ext a |
It also works when I use an OnInput trigger to set up the pp() function rather than using the setlua alias.
The only part of this that still doesn't work properly is the "a" alias:
Code: |
<alias name="a" copy="yes">
<value>#LUA {pp()}</value>
</alias> |
when I type "a this is a test", the pp() function is not able to grab the original arguments of the alias. This is because the #LUA command creates another execution block without any arguments. Essentially, the #LUA command is it's own alias, so zs.numparam is returning the number of arguments to the #LUA command, and not the original alias.
I've left this last problem on the bug list to see if it's something I can fix. But at least the major problems with Lua scripts seem to be fixed now. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Feb 05, 2009 7:03 pm |
OK, I've got the "a" alias working now too. There was an extra stack frame being pushed that was causing the problem.
I've got some more Lua issues still on the bug list that I will test later today, but I think this generally will solve a *lot* of the Lua issues that were being caused by corrupted stack frames getting the wrong thread values. It's all a lot cleaner now. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Feb 05, 2009 7:23 pm |
All I can say is Super Sweet!!!!
|
|
_________________ Asati di tempari! |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sat Feb 07, 2009 3:15 pm |
Any idea on a timeframe for 3.04 being released? :-)
I'd like to start using Cmud again. Honestly one reason I would like to completely convert to Lua for all my scripts is that it is a real scripting language used every day in real life. As far as I know there isn't anyone out there using zscript. So you have the benefit of scripting in a real scripting language that can be used elsewhere and becoming good at it. I'd like to see a little better implementation of it as well. For example, when it comes to buttons, being able to change the captions etc... if that is possible? |
|
|
|
|
|