The Daily Click ::. Forums ::. Klik Coding Help ::. Questions about lua!
 

Post Reply  Post Oekaki 
 

Posted By Message

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
30th October, 2009 at 19:39:21 -

Ok so I've been messing around with lua because I need to implement it in one of my projects.

I understand that Xlua is considered the best variation of the lua extension, but I have yet to be able to do anything with it. The regular lua extension seems a bit easier to use as well.

Anyways a couple of questions:

-Is it possible to load all of the scripts that will be used into memory from files at runtime?
-Can multiple scripts be ran at once in a loop?
-Can variables inside lua be changed by mmf? (ex. have a command like this: "print ($text)" and have mmf change the variable $text)
-Can a function be made that allows lua to gather data about anything inside mmf, like: getplayerx()

-Can someone make an example of a script reader with custom functions that uses the Xlua objects?

Thanks!


 
n/a

bigredron



Registered
  07/04/2007
Points
  299
31st October, 2009 at 02:45:38 -

xlus is defiantely the best lua extension to use.

To answer your questions;
-Is it possible to load all of the scripts that will be used into memory from files at runtime?
YES. dofile("name.lua") is the function you call in your script

-Can multiple scripts be ran at once in a loop?
Im not sure what you mean. When you execute a script it will read it from top down and do any events that are within that. Same as when you call a function.

-Can variables inside lua be changed by mmf? (ex. have a command like this: "print ($text)" and have mmf change the variable $text)
You need to pass values and variables into LUA and vice versa. Lua can also read and write to objects in MMF if you have MMF interface selected.

-Can a function be made that allows lua to gather data about anything inside mmf, like: getplayerx()
Yes, see above. Turn on MMF interface. I suggest you read the help file.


Hope that helps

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
31st October, 2009 at 15:42:48 -

Thanks for your help.

When you say "dofile("name.lue")" does that mean It'll grab that file and load it into memory so that the original file can be deleted off the machine, but still run?

I want to run multiple scripts that apply to the same active objects, but at the same time change the varibles in that script to the Alterable Variables of that object. Like so:

MoveObject(getA()+5,getB()-3)

and getA() gets the Alterable Value A of whatever object it is that the script is manipulating.

I'm having a hard time explaining. Thanks for the help though. I'll go read the documentation, but the examples didn't help me much.

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
31st October, 2009 at 20:51:38 -

Ok, it seems people like to have example files to play with, so here ya go!

http://www.jsoftgames.com/luayeilding-EditedXlua.zip

I can't get this to work. I replaced all the commands from the original lua example to work with Xlua, but it's not!

Can anyone fix this for me?

Thanks

 
n/a

bigredron



Registered
  07/04/2007
Points
  299
31st October, 2009 at 23:48:30 -

I see you are using Zephni's coroutine example.
Coroutines I dont really know much about and I wouldnt suggest you even bother looking at this unless you want to make a scripting engine. Coroutines pause your application which is what is needed for scripting.

To interface with objects directly you need to tick the box under xlua properties which says 'enable MMF interface'.
Look at the example file that is supplied with the xlua zip file. One of them shows how to interface with MMF directly.

What you need to do is export all your objects into a LUA table so that it can reference them later. This can be the fixedvalue of the object or a custom ID value, it doesnt matter as long as you can select the right object.
Once you have the IDs stored in a LUA table you can then do commands such as mmf.Object.GetValue(ID,1) which will return Alt value A for the unit exported with that ID. You can also write to the Alterable Value by using mmf.Object.SetValue(ID,1,999) which will set Alterable Value A of object with ID to 999.

Take a look at the help file under 'MMF interface' which lists all the different interface functions. You can also change objects positions, order and many other things.

In regards to dofile("file.lua") command, this simply includes that script into memory exactly how 'include' works with C/C++.
Wether you can delete this once it has been loaded into memory is something you will have to test but if you were worried about people having access to your file include them in string objects instead within MMF or use the binary object to pack/unpack them only when you are loading (this is what I do)

You should also post in Clickteam forums which have a dedicated LUA section. Retriever2 always answers any questions you have, he made the xlua extension.

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
1st November, 2009 at 00:24:55 -

Alright I might just head over to the clickteam forums. However I think I'll just stick with the regular lua extension since it seems easier, and I don't really want to do a super complex system. Just for character dialog and such.

I'll most likely make a custom setup that uses lua and a custom scripting engine combined.

Also I have to store the files externally because, you see they need to be updated periodically over the internet. That's why I need to load them into memory at runtime somehow and then delete them, or in the very least make them virtually inaccessible. I think I'll just blowfish encrypt them or something.

 
n/a

bigredron



Registered
  07/04/2007
Points
  299
1st November, 2009 at 00:49:29 -

I would strongly advise to use xlua extension.
One of the LUA extensions is no longer being updated (Jamie's one) and the other one is very basic. XLua is only complex if you need it to be. Its continuously being updated too and the author is there to answer all your questions as I mentioned in my last post.
Its up to you though

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
1st November, 2009 at 00:51:14 -

ok then could you get the example I posted working correctly? If you do I can simply examine the code and figure out how it works!

 
n/a

Xgoff



Registered
  22/02/2009
Points
  135
1st November, 2009 at 19:40:58 -

i don't think xlua can call mmf functions through coroutines; i asked rii about and he didn't say anything about it being intentional (specifically he said it could be due to how xlua handles its call stack or luajit's way of handling coroutines)

for now you'll probably have to use the regular lua object, but if this can be fixed you will definitely want to look into using xlua instead

 
Image

bigredron



Registered
  07/04/2007
Points
  299
1st November, 2009 at 23:20:46 -

I dont see how xlua would not be able to handle the coroutines, its part of the LUA code...
All these extensions do is allow MMF to link in with LUA scripting. I will play with the example and see if I can get it to work later.

EDIT: ok you are right, for some reason coroutines dont seem to work with xlua. Well they might work, just not the way that Zephni's example works. Actually now that I think about it I did try to get coroutines working before but couldn't get it working, I wonder if thats why...

Edited by bigredron

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
2nd November, 2009 at 01:06:26 -

Hmmm, so coroutines don't work with xlua?

Odd.

Thanks for the help guys it means a lot!
Could one of you perhaps make a scripting engine using xlua? Or is that impossible?

If no one here can do it I'll just use the regular lua object.

Thanks so much!

 
n/a

Xgoff



Registered
  22/02/2009
Points
  135
2nd November, 2009 at 03:48:49 -


Originally Posted by bigredron
I dont see how xlua would not be able to handle the coroutines, its part of the LUA code...
All these extensions do is allow MMF to link in with LUA scripting. I will play with the example and see if I can get it to work later.


if it were due to the c function stack that would be why; apparently it can be quite difficult to communicate with mmf without crashing it, and calling c functions when it doesn't expect them is one way to blow it up (which is why there's two different calling modes for the print and error queues: "Queued" is far less likely to crash mmf but is limited to the size of the event queue [which is only like 20 or something], and "Immediate" isn't limited to the queue size but can desync with mmf and crash it)

luajit itself apparently makes changes to how coroutines work with c functions, to make them more efficient for the compiler and to also remove some restrictions that are normally there (specifically with coroutine.yield()). this could also be another factor if it's not playing well with mmf

the original lua object is probably just a straight-up embedding of lua into an extension so it doesn't have this problem as it doesn't have the features that could cause it

anyway, coroutines do work in xlua, but only inside lua code; if you try to call functions inside mmf from inside a coroutine, nothing will happen in mmf and the coroutine will just continue on its way

Edited by Xgoff

 
Image

bigredron



Registered
  07/04/2007
Points
  299
2nd November, 2009 at 05:08:57 -

Xgoff:
You are right about some sort of C error.
I did an OnError function in MMf events and printed the result to the popup box.
See this link: http://img511.imageshack.us/img511/9712/xlua.jpg
Not too sure what it means though, i dont have C experience.


UrbanMonk:
You can probably do a dirty workaround by storing your script in a lua table.
Then you would have some sort of counter to keep track of the line number and pull the appropriate string from the table. You would call the function 'say' every time the user presses key to continue.
Similar to this:

** IN LUA **
script={"first sentence","second sentence","third!","and last but not least, four!"}
LineNumber = 1

function say()
print(script[LineNumber])
LineNumber=LineNumber+1
end


** IN MMF **
+ Upon pressing enter
-> Call function "say"


I'm sure there are other ways too, you just need to be creative



Edited by bigredron

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
2nd November, 2009 at 12:40:22 -

This kinda ruins the whole idea behind using lua. I was gonna use it to make dialog easier.

Do you think I could perhaps store the lines inside of a text array, and call each line from there?
I could just make my own pause command. hmmm.

Since I'm not using c code for anything I'll most likely just use the regular lua object for simplicity sake.

Thanks so much guys. If you think of another way around this let me know! I'm curious about this now.

 
n/a

aphant



Registered
  18/05/2008
Points
  1242
2nd November, 2009 at 15:09:11 -


Originally Posted by bigredron
Xgoff:
You are right about some sort of C error.
I did an OnError function in MMf events and printed the result to the popup box.
See this link: http://img511.imageshack.us/img511/9712/xlua.jpg
Not too sure what it means though, i dont have C experience.



Those are Lua errors, coming from lines 7, 12, 43, and 61 of data.lua. The first three errors are within functions, the last one is not. I can only guess that these errors are because you're calling the yield function wrong.

 
   

Post Reply



 



Advertisement

Worth A Click