-
Notifications
You must be signed in to change notification settings - Fork 13
WDL ~ Lua Scripting and WDL
Based on the new WDL++ specification written by the WDL team, this document describes on a high-level how lua scripts can be implemented to allow for action sequence chaining that could be useful for custom actions.
Below is an example of how custom actions can be implemented in WDL++ (taken from Feature Wishlist wiki page (https://github.com/uchicago-cs/chiventure/wiki/Feature-Wishlist#custom-actions)
{
"action": "LIFESTEAL ", // designate the LIFESTEAL command with 1 variable- target
"help": "Steals 2-10 health from the target and restores it to the user", // for displaying in the help screen
"environments": [ "combat" ], // allow this command only in a combat environment
"sequence":
[
{ "block": "assert self mana 4"}, // see if the user has 4+ mana left, otherwise exit the sequence (self refers to the user)
{ "block": "stat self mana - 4"}, // see if the user has 4+ mana left, otherwise exit the sequence
{ "block": "generate_rand i 2 10"}, // generate a random number between 2 and 10 and store in i
{ "block": "stat target health - i" }, // decrease the target's health by i
{ "block": "stat self health + i" }, // increase the caster's health by i
]
}
According to WDL++ team, we can call Lua script to execute a block of action by passing in path to .lua file and arguments (e.g: name of the action we want Lua to execute) to pass into Lua functions:
{ "action": "act_PUSH",
"sequence": [
{"block": "if", "params": "inventory has item_SPINACH"},
{"block": "set", "params": "obj_CHAIR flipped"},
{"block": "say", "params": "'You pushed the chair. It flipped!'"},
{"block": "else", "params": ""},
{"block": "say", "params": "'Couldn't push the chair. Spinach needed.''"},
{"block": "endif", "params": ""},
{"block": "say", "params": "'This is printed regardless of push success.'"},
{"block": "lua", "params": "'path/to/example.lua' arg0 arg1 arg2 arg3"}
]
}
To use Lua, we can have a C module that deals with loading and running Lua script:
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
A struct that holds lua_State, which is like a stack. All data exchange from Lua to C and from C to Lua occurs through this stack
typedef struct _lua_state {
lua_State *L;
} Lua
This function loads the lua_State from lua file
lua_State *LoadLua (char *filename) {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
luaL_dofile(L, "filename.lua");
lua_setglobal(L, "filename");
lua_settop(L, 0);
return L;
}
This function goes into lua, find the function that we want Lua to operate, pass in the objects or data we want Lua to operate on, and return the data that that Lua function changes. This is just a very high-level view to see how WDL++ parsing can work to produce arguments for this runLuaFunction. Eventually, if we want Lua to change different things about the game (action, items, dialogue), we would have to think more about what data from the game we want to pass to Lua
void* runLuaFunction (char filename, char functionname, void* userdata) {
Lua *L = malloc(sizeof (Lua));
Lua->L = LoadLua (filename);
lua_getglobal(Lua->L, "functionname"); // push the function on top of Lua stack
lua_pushuserdata (Lua->L, userdata); // push userdata on top of Lua stack
lua_call (Lua->L, int numArguments, int numReturnValues); // call the function
return lua_touserdata (Lua->L, int stackLocation); // extract the data off Lua stack
}
In accordance to WDL++ team’s visualisation of how Lua scripting could work in sequence action chaining:
{"block": "lua", "params": "'path/to/example.lua' arg0 arg1 arg2 arg3"}
We can change it to something like this so WDL++ file can parse these parameters and extract them into runLuaFunction function:
{"block": "lua", "params": "'path/to/example.lua' 'functionname' arg0"}
Lua scripting can be implemented in other parts of the game other than custom actions, such as NPC and Game State using the same WDL++ interaction to create new game states and NPC dialogue.
-
Action Management
-
Battles
- Design Document
- Text Based Combat in Other Games
- User Stories
- Wishlist
- Battle Planning 2022
- Battle User Stories Review 2022
- Structs in Other Modules Related to Battles 2022
- Stat Changes Design Document
- Run Function Design Document
- CLI Integration Design Document
- Move Changes Design Document
- Unstubbing Stubs Design Document
- Battle Items and Equipment Design Document
- Battle Item Stats
- Battles Demo Design Document
- Battles Testing Moves, Items, and Equipment Design Document
- Sound integration with battle (design document)
-
Custom Actions
-
Custom Scripts
-
DSL
-
CLI
-
Enhanced CLI
-
Game-State
-
Graphics
- Design Plan
- Design document for integrating split screen graphics with chiventure
- GDL (Graphical Description Language)
- Graphics Sandbox
- Design Document for NPC Graphics and Dialogue
- Feature Wishlist (Spring 2021)
- Installing and Building raylib on a VM
- LibSDL Research
- Module Interactions
- Working with Raylib and SSH
- raylib
- GDL
-
Linking the Libzip and Json C to chiventure on CSIL machines
-
Lua
-
NPC
- Dependencies: Player class, Open world, Battle
- Action Documentation
- Design Document for NPC Generation in Openworld
- Design and Planning
- Establishing Dependencies
- Implementation of Custom Scripts
- Independent Feature: NPC Movement Design Document
- Player Interaction Design and Planning
- Dialogue
- Design Document for NPC Dialogue and Action Implementation
- Loading NPCs from WDL Files
- NPC Battle Integration Design Document
- NPC Battle Integration Changes Design Document
-
Open World
- Autogeneration and Game State
- Deciding an integration approach
- Designing approach for static integration into chiventure
- Feature Wishlist
- Generation Module Design layout
- Potential connections to the rest of chiventure
- Single Room Generation Module Design
- Source Document
- User Stories
- World Generation Algorithm Plan
- Loading OpenWorld Attribute from WDL
-
Player Class
-
Player
-
Quests
-
Rooms
-
Skill Trees
- Avoiding soft locks in skill tree integration
- Components of Exemplary Skill Trees
- Design Document and Interface Guide
- Environment interactions based on skill characteristics
- Integrating complex skill (combined, random, sequential, etc.) implementation
- Integration of a Leveling System
- Potential Integration with existing WDL
- Research on game balancing in regards to skill trees
- Research on skill tree support in modern day game engines
- SkillTree Wiki Summary
- Skilltree "effect" implementation and roadmap
- Summary of md doc file for skilltrees
- Design ideas in connection to other features
- Summary of Skill Tree Integration 2022
- The Difficulty of the Reading the World
- Complex Skills Summary
-
Sound
-
Stats
-
WDL