Jump to content
  • Advertisement
Sign in to follow this  
javasirc

Unity Creating scripting engine, need help

This topic is 1442 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive been trying to get a scripting system integrated into my game, to change variables and access object information. Im using C# Visual Studios Express 2012, Monogame, and XNA GS 4.0. I installed Lua, but got an error saying its not compatible with XNA 4.0. I tried NLua and IronPython, but i cant figure out how to get them to work. Ive been experimenting with Reflection and CSharpCodeProvider to compile code. Ive successfully loaded and compiled simple "scripts" that have no interaction with my actual game.

 

Im trying to load a script, and have the script change variables within my game. I have no idea how to allow the script to get my game's variables or classes so it can change/access them. Is it possible to have a script change any game variable? With Reflection? Does anyone have any code examples or sites that can teach me how to create my own script engine? Most of my google results come up Unity related, so im having a hard time figuring this out. Is there a step-by-step tutorial for setting up NLua with C# XNA 4.0? Im becoming very frusterated with this scripting stuff.

Share this post


Link to post
Share on other sites
Advertisement

I started using NLua only a few weeks ago, so I'm not an authority on it. However, I've managed to get lua scripts to interact with my game objects, which sounds like your goal?

 

To give Lua access to my .net entities I set them in the Lua script object itself. eg:

 

// Set the reference to the object that the lua script will have access to.
_lua["this"] = Owner;

 

Then in the lua script I can access the "Owner" object through the identifier "this".

 

Here is an example of a script I was using for testing:

 

function OnSpawn()
    local type = this:GetComponentByName("GeneralPropertiesComponent")
    return type
end

The thing that tripped me up for a little while was the ":" (colon) that was needed between the object and the method name.

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!