logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
nwnx_funcs for windows
Goto page Previous  1, 2, 3 ... 27, 28, 29
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
highv priest



Joined: 01 Mar 2013
Posts: 111

PostPosted: Sun Dec 18, 2016 3:46    Post subject: Reply with quote

I ran into an issue, it won't load, says the specified module wasn't found.
Back to top
View user's profile Send private message
Terra_777



Joined: 27 Jun 2008
Posts: 216
Location: Sweden

PostPosted: Sun Dec 18, 2016 21:01    Post subject: Reply with quote

https://github.com/TerrahKitsune/NWNX/releases/download/v0.0.1/lua52.dll needs to be in the nwn root aswell
_________________
I dun have any signature, I'm happy anyway.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
highv priest



Joined: 01 Mar 2013
Posts: 111

PostPosted: Wed Dec 21, 2016 7:36    Post subject: Reply with quote

Forgot to post, that did it.
Back to top
View user's profile Send private message
Valgav



Joined: 28 Aug 2010
Posts: 53

PostPosted: Sat Jan 07, 2017 18:24    Post subject: Reply with quote

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
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Jan 09, 2017 19:42    Post subject: Reply with quote

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
View user's profile Send private message
Valgav



Joined: 28 Aug 2010
Posts: 53

PostPosted: Mon Jan 09, 2017 23:08    Post subject: Reply with quote

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
View user's profile Send private message
Terra_777



Joined: 27 Jun 2008
Posts: 216
Location: Sweden

PostPosted: Thu Jan 12, 2017 20:37    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail MSN Messenger
Valgav



Joined: 28 Aug 2010
Posts: 53

PostPosted: Sat Jan 14, 2017 18:22    Post subject: Reply with quote

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
View user's profile Send private message
Valbor



Joined: 26 Dec 2016
Posts: 145

PostPosted: Mon Jan 16, 2017 9:41    Post subject: Reply with quote

Terra_777 wrote:
The lua functions: http://pastebin.com/FZP7xgWB
Where to get it: https://github.com/TerrahKitsune/NWNX

Explain to me how to use it? I downloaded NWNX-master and lua52.dll, what's next?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Goto page Previous  1, 2, 3 ... 27, 28, 29
Page 29 of 29

 
Jump to:  
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