Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Best Thoughts For Lua Implementation

Author
Message
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 21st Feb 2010 22:40
I want to hear thoughts on ways to implement lua into a GDK program. I've heard of barnskies lua plugin but what i've seen is vague.

Aldur
17
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 21st Feb 2010 23:09
I have heard LuaBind is pretty good, yet to use it though.

It can be found at http://www.rasterbar.com/products/luabind.html

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 23rd Feb 2010 09:33 Edited at: 23rd Feb 2010 10:01
Here are some references I've used to implment DarkLUA:

http://www.codegurus.be/codegurus/Programming/luaintroduction_en.htm
http://gamedevgeek.com/tutorials/calling-lua-functions/

Once you're able to run a basic script than the implementation begins. I'm curious to how you intend to use scripting. I see a lot of folks add LUA then want to bind every single DGDK function to implement some sorta soft engine. In my opinion its not necessary and for performance sake scripting should be targeted at Configuration setup, dynamic format data, and Logic for AI.

I designed the DarkLUA Scripting System with the goal of building Applications and AI in a hierarchal and
modular fashion using self contained blocks of script called Batches.

Application Hierarchy:

Batch -> Task/Job -> Service -> Applet -> Application

1. Batch = a text file or string containing a series of Script Language commands. It can be
embedded in between other text such as a markup Language.
1b. Macro = Name Key associated to a Batch that can be embedded in other scripts.

2. Task = A dependent Batch procedure attached and controlled externally by another object or
2b. Job = is a independent Task procedure controlled internally. It uses FSM to manage its
own state.

3. Service = A group of Tasks that work together to perform specific functions within a Application
without user input. Each Task or Job can effect the state of each other.

4. Applet = A group of Services that work together within a Application that may or may not require
user input. A CLI or GUI is usually applied to frontend for use by a user.

5. Application = A series of Applets integrated together.

AI Hierararchy:

Finite State Machine
EventState Triggered via Condition Check (comparison, collision, input state checks)

- Action = Batch that executes during a particular EventState.
- Behavior = Batch that manages an Object's EventStates.
- Transition = Batch that executes between Event State transition.
- Global Event = Series of Object Actions triggered by one or more Object EventState Changes

Neural Network and Genetic Algorithms [conceptual]
- Node
- Neurode

entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 23rd Feb 2010 11:38 Edited at: 23rd Feb 2010 11:39
You're absolutely right, TechLord. Binding the entire GDK only leads to you having to write the same code twice and for the engine to be prone to leaks following dynamic allocation. It's also a nightmare to debug.

Engine instructions and internal game logic is best handled in C++. The intention of using a scripting language should be to provide an interface to the stuff you do often and the stuff you need to tweak, so you don't have to recompile every single bit of polish. The easier the interface, the faster the iteration. And the more people can help you.

On an application level, you can configure resolution, profile names, key bindings and similar in script.

On a game level, you can have AI state machines, links to level assets, textures, object loading, etc in the script. The actual "game," really.

You'd want to come to the point where you can write the following:



...and let the game handle the rest.

I've been having some trouble implementing Lua myself and decided that it wasn't quite worth the effort, even though I like the language extremely much and use Lua in several other projects. I simply wasn't a good enough C++ programmer to implement it on my own.

Instead, I chose to use something called GameMonkey Script, and that's a decision I'm so far praising myself for.

It's extremely simple to set up -- it took me less than half an hour to bind my first function. And it's also a lot more efficient for game-making, as it has built-in functionality for states, threads and stuff that you'd generally need to have to make an AI system or, as in my case, to write gameplay logic.

You can read all about it on GameDev:
http://www.gamedev.net/reference/programming/features/gmscript1/
http://www.gamedev.net/reference/programming/features/gmscript2/
http://www.gamedev.net/reference/programming/features/gmScriptAdv/

And you can download it here:
http://www.somedude.net/gamemonkey/

The two first articles on GameDev were enough to get me started, actually. I also found some other useful links in my searches, in case you're new to C++.

How to build the .lib:
http://www.ceegeepee.com/grellin/?p=105

How to override the default print() function:
http://www.facepunch.com/showthread.php?t=580202
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 2nd Apr 2010 15:51
How did you get GameMonkey to work, I've tried all combinations of compiling the GM lib as /MT MTd in debug, release etc, including matching my project's config but all of them give errors on compile as soon as i use:



Just the include is ok, but i cant create a gmMachine or do anything with it then obviously. I think Ive got it set up properly according to the links u posted above, the src as include and the compiled lib as an additional dependency.
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 2nd Apr 2010 16:42
Not sure, but I think these "<>" are reserved for built-in includes. Try to write:



Not sure that it actually makes a difference, but it's something.

What errors are you having? Could you paste the VS error log?
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 2nd Apr 2010 18:54
oh, lol ok, I just attempted to go through each possible configuration again to post each set of errors but one of them worked this time, I have a feeling I accidentally set my code generation to /MD for the library, instead of /MT

For anyone else that comes across this problem:


As an aside can you post any examples or anything of Dark GDK things you have managed to bind so far? I'm about to start that next and have no real idea.
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 2nd Apr 2010 21:49 Edited at: 2nd Apr 2010 21:50
I'll post the entire code for the first test app I wrote. Hope it helps!



Most of it is based on the GameDev articles I linked before, by the way. Creds where creds are due, after all.
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 3rd Apr 2010 05:59 Edited at: 3rd Apr 2010 13:34
Thanks, v much, that's a lot to look over, ill have to see I did have a look at the gamedev articles as I was setting up but then it seems gamedev's domain registration ran out so I can't see them anymore.

EDIT: I got it to work, interestingly, when dbPrint is called via the overridden print function ir only works ie, you can only see the text if the 3d backdrop in DarkGDK is off, using dbBackdropOff(). Normal C++ calls to dbPrint work as normal.
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 4th Apr 2010 09:34 Edited at: 4th Apr 2010 09:36
Can I be a real pain and get you to post an example script that for that c++ code? I'm having trouble registering the c++ stuff I've bound and then getting it to do anything from script. I was just testing with some basic ones like this:

entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 4th Apr 2010 12:21
How does it look like in the actual library binding? The functional declarations is just one step: you need to first store the actual in-script function names somewhere and then bind them to the virtual machine.
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 4th Apr 2010 12:52
Yeah that is the part that I don't understand, library binding wha? I thought i could call this in my script:


and it would register and use the function...
Obv not.
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 4th Apr 2010 13:07
Ah! Then that's where you're doing it wrong.

First, create a binding against GameMonkey:



Then, after instantiating the VM, tell the VM to load that library:

Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 4th Apr 2010 15:33 Edited at: 4th Apr 2010 15:36
Ok, i really hate to bug you again, so ty very much for your help so far and your help in advance, but I cant work it out. I have your other functions in there for loading and error handling, and I can get it to print to screen using the overridden print function by loading a script "test.gm" with print(`hello world`); in it. I have the following before my GDK loop:



and

inside my test.gm, and I know this must be the problem, but I don't know what I should have different.

Please enlighten me!
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 4th Apr 2010 15:50
I think this is a scoping issue, actually.

Try putting these:



...inside the "void DarkGDK( void )" step, but still outside your main loop.
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 4th Apr 2010 16:39 Edited at: 4th Apr 2010 18:56
They are, and they are also after I have created the object number 3, so its not that either. Only:

Is outside the void DarkGDK( void ) step, for obvious reasons. I wonder what else I'm missing.
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 4th Apr 2010 16:57
I couldn't compile your code, because I don't have the "Fulcrum Physics" plugin, but I think I could see something you might try, at least.

Move this:



...to the outside of the DarkGDK( void ) scope, somewhere around line 225 in your code.

A bit of advise, as well: it's rarely a good idea to bind core functionality to script. You want a script to execute commands like "AttackPlayer()" or "Flee()" -- not low-level logic, like rotation, etc. Such numbercrunching is better handled by the C++-side of a game and also a lot easier to debug when it's not handled by a virtual machine.

Really: the code I submitted a few posts ago includes an entire GameMonkey solution. Try playing with that a bit more to see what goes wrong in your own solution.

I don't mind answering questions, but I'm not interested in solving issues that you could easily solve yourself with a bit of tinkering.
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 4th Apr 2010 18:53 Edited at: 4th Apr 2010 19:12
Ok well thank-you for your help so far, but trust me, I did plenty of tinkering before asking for help, GM just seems woefully documented.

I tried moving it, made no difference. I figured it was the way I called it in my GM script since I don't have a script that has a bound c function to look at, I took a guess at that.

I don't want the script do any low level logic like rotation, but I will definitely call more complex c bound functions that have the dbRotate() in them, like AttackPlayer() for eg, would rotate towards player, check distance, play sound and animation, deduct damage from health variables etc. So if I can't get GM to call a c function that has just dbRotate() in it, there is no chance I'm getting it to do all that.

EDIT: I have discovered something that does effect things, if a function expects a float, such as setObjectPosition(objectNo, X, Y, Z) X, Y, and Z are floats, if you call it like this from GM in your script:

It will fail, you must explicitly do this:

Quote: "The rule is that whenever different types are used together, the higher type is preserved or used. The types from low to high are int, float, string."
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 4th Apr 2010 19:20
You're absolutely right. In fact, values in GM change over the course of time. If you increment a variable by 0.5, for example, it will go between int and float on every increment; e.g., 0.5 (float), 1 (int), 1.5 (float), etc.

This is the code of GM/test.gm that I used together with the binding code I posted:




And this is the code of "GM/test2.gm":



One cause for headache can also be the fact that GM is case-sensitive. But this is nothing new to someone programming C++ in the first place, so it's actually a boon more than a curse when switching between the two languages.
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 5th Apr 2010 19:23
Any luck, so far? Did you solve your issues?
Matt G
20
Years of Service
User Offline
Joined: 26th Oct 2004
Location: Australia
Posted: 6th Apr 2010 07:48
Yes ty, it was just the float issue in the script, and gamedev is back up now so its rolling along nicely. Thank-you again for your help.
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 6th Apr 2010 09:06
I suggest looking into GM threads once you get things rolling nicely. It's superb for creating AI state machines and similar, or to make script triggers of one kind or another.

Login to post a reply

Server time is: 2024-11-20 01:42:49
Your offset time is: 2024-11-20 01:42:49