View previous topic :: View next topic |
Author |
Message |
highv priest
Joined: 01 Mar 2013 Posts: 111
|
Posted: Sun Dec 18, 2016 3:46 Post subject: |
|
|
I ran into an issue, it won't load, says the specified module wasn't found. |
|
Back to top |
|
|
Terra_777
Joined: 27 Jun 2008 Posts: 216 Location: Sweden
|
|
Back to top |
|
|
highv priest
Joined: 01 Mar 2013 Posts: 111
|
Posted: Wed Dec 21, 2016 7:36 Post subject: |
|
|
Forgot to post, that did it. |
|
Back to top |
|
|
Valgav
Joined: 28 Aug 2010 Posts: 53
|
Posted: Sat Jan 07, 2017 18:24 Post subject: |
|
|
So I was thinking about coming back to coding in nwn and have question about this lua lib. Is it for lua being called from nwn or to call nwn from lua?
Also does:
Code: | void MainLoopHook( function ) - hooks nwn's mainloop and runs the function every frame. void func() |
can be stop? So force some task to do on Main loop than remove it from main loop because what I understand it works like while(true) { function } |
|
Back to top |
|
|
Baaleos
Joined: 02 Sep 2007 Posts: 830
|
Posted: Mon Jan 09, 2017 19:42 Post subject: |
|
|
I think the MainLoopHook is mandatory, as it is about protecting the variables and memory within nwn.
Eg:
Everything in nwn runs within the MainLoop - every nwscript call is done sequentially.
If you were suddenly able to invoke LUA scripts, outside of the MainLoop's context, you run the risk of local variables and even arguments that are being passed to internal functions, getting mixed up and contaminated.
I've seen instances in the past where I was experimenting with invoking internal functions within the server process from outside of the mainloop.
The results were sporadic, on some occasions when I triggered the SpeakString method, the module would speak the string on shout channel, on other occasions, it would pass the string to the first placeable object it found etc.)
The thing to remember in programming, is that everything boils down to your typical assembly (ASM) calls.
You end up with variables called eax, ecx, ebx and so on.
There is only so many of them...
If you execute a NWScript call to SpeakString, it is going to pop the register that equates to the designated speaker, into one of those registers.
However, if you make a call to a NWScript function from outside of the mainloop, you run the risk of
1. Using the value from that previous script in your external call.
or
2. Your external call, will overwrite the register values being used by the first NWScript call.
So the thing to remember is
Yes - Programming in LUA or Java may give you the ability to execute code outside of the mainloop - however, its not always a good idea to do so.
There are exceptions to this rule however.
The only reason you need to be on the MainLoop is if you have the intention of interacting with the Server or creatures / objects inside the server.
If you are running your own code that never has to inject back into the nwserver process, then you could escape the MainLoop.
But you need to be aware, that once you leave that loop, its very hard getting back in.
I have my own Java code that does the entirety of a complex heartbeat system for a subrace engine I made.
It has to run as a creature on the module, in order to keep itself within the Mainloop.
Running it on another thread led to instability.
Java and Lua may yet give you enhancements that make it worth while staying on the mainloop. |
|
Back to top |
|
|
Valgav
Joined: 28 Aug 2010 Posts: 53
|
Posted: Mon Jan 09, 2017 23:08 Post subject: |
|
|
Is there any working example of implementation for lua? I would love to give it a shot by don't want to reinvent the wheel and setup whole framework from scratch. |
|
Back to top |
|
|
Terra_777
Joined: 27 Jun 2008 Posts: 216 Location: Sweden
|
Posted: Thu Jan 12, 2017 20:37 Post subject: |
|
|
Except; lua doesnt replace the existing or run in the existing virtual machines place. It also runs on nwns thread, lua itself isnt multi threaded, you can have concurrent threads but you'll only ever have one running at the time.
Only function in lua that does anything with the virtual machine is the "NWScriptFunction( proc-address-string, opcode, secondarg, ... )" function which is just a dirty call-memory-pointer kind of deal, it works ok for simple functions such as GetName, etc but it does not work with complex types such as item properties, effects.
Objects in lua is just a hex string of the object, ie "0" = module, "1" = first area, "2" = first object in area. The nwscript function ObjectToString is compatible with it.
As for frameworks, I havent really done much with it, biggest system I got was overriding the chat routines from the on_chat nwscript event. Other then that its mostly small snippets to functions otherwise not available in nwn as well as access to lua's array/table functionalities on a global persistent environment. _________________ I dun have any signature, I'm happy anyway. |
|
Back to top |
|
|
Valgav
Joined: 28 Aug 2010 Posts: 53
|
Posted: Sat Jan 14, 2017 18:22 Post subject: |
|
|
So you wouldn't advise to use this for more sophisticated cases to use advantage of lua classes, lists etc. to maintain some heavier algorithms?
I'm thinking about some sort of pseudo RadiantAI implementation. In fact in background it's just simple state machine based on table with information:
WHO is WHERE and WHAT does. To load correct npcs or object when loading area. But It would be very difficult to does this using nwscript.
Also would you be so kind to provide me your samples of code? |
|
Back to top |
|
|
Valbor
Joined: 26 Dec 2016 Posts: 145
|
Posted: Mon Jan 16, 2017 9:41 Post subject: |
|
|
Explain to me how to use it? I downloaded NWNX-master and lua52.dll, what's next? |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|