Skip to content

Custom Scripts ~ Using Custom Scripts

RamarkoB edited this page May 18, 2022 · 4 revisions

How Does Lua Work?

The first thing necessary for understanding custom scripts is understanding the interactions between Chiventure and Lua.

For the purpose of Chiventure, Lua is a way to store information. We can pass in arguments to Lua in the form of Functions, Ints, Bools, Chars and Strings. This information is stored in the Lua Game State, and it can be accessed and changed through an Instance of Chiventures. Everything in Lua is being stored on the stack, and can be popped off the stack and returned to C at any point. Lua will return a virtual pointer to the position of the variable or function for easy access.

What does Custom Scripts do?

What custom scripts does is handle most of the more complex parts of dealing with Lua. Custom Scripts will handle initializing the Lua game state, and will record where you put your variables and functions in the Lua stack. When you pass something to Lua, Custom Scripts will create a struct that will record what type of information you've stored in Lua, and return the pointer to the struct.

Afterwards, you can use the pointer to access and change the information in the Lua stack at any point, making it significantly easier to create a more dynamic game in Chiventure

How can I use Custom Scripts to make my game in Chiventure more interesting?

Custom Scripts allows you to dynamically generate different things depending on what you want to do.

One example is custom strings. You can use Custom Scripts to remember the player characters name, and make all strings then change to match the player's name from that point forward.

Another example is conditional actions. You can store a boolean value or an integer in Lua, and make actions dependent on that variable. You can make custom scripts so that an action is only possible if a certain item is in your inventory, or if you have a certain amount of coins.

The purpose of Custom Scripts is to make Chiventure more dynamic! Use Custom Scripts to make your game more unique and responsive!

That's super cool and all, but how do I actually use Custom Scripts?

The Interfacing functions of Custom scripts are the Object functions and the Get functions. The object function will store your variable in the Lua Stack, and return a pointer to a struct that will preserve all the information Lua has returned to find your variable. Afterwards, you can use the get function to return the variable you have stored in Lua using the pointer the the struct you have.

If you have a more complex understanding of Lua, it is also possible to create functions to interact with your variables and create a more dynamic game environment.

Clone this wiki locally