Scripts / [MAX] Dynamic Lua explanation

Author
Message
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 23rd Mar 2022 17:21 Edited at: 23rd Mar 2022 17:30
not sure if this has been covered yet so i'll give a basic run down of how to use the new dynamic lua system in Max

firstly the scripts in Max require a comment at the top of the script to work
--DESCRIPTION: this script does...
great, now the script can be assigned in max and you can keep track of what the script does... but that's only the beginning

these description comments also gives you access to the dynamic lua - i.e. the ability to change the settings in the editor
basic usage is enclose a variable name with a default value inside some square brackets
e.g.
--DESCRIPTION: [VARIABLE=1]

you can add text outside the brackets to help explain what it does
e.g.
--DESCRIPTION: This [VARIABLE=1] can be accessed in the script

currently there are a few different things we can get access to using this method
--DESCRIPTION: [MY_NUMBER=1]
will let you access an integer value for the variable MY_NUMBER to use in the script
*how to use the variable i will explain after*

--DESCRIPTION: [MY_NUMBER=200(100,500)]
will let you access an integer value as above but this time between 100 and 500 (inclusive) and will be set to 200 by default

--DESCRIPTION: [MY_STRING$="hello"]
will let you change the string "hello"
*note the $ at the end of the variable name, this is required to tell the system it is a string*
(you will not need the $ when referencing the variable later)

--DESCRIPTION: [MY_NUMBER#=1.5]
will let you access a float number (set to 1.5)
*note the # at the end of the variable name, this is required to tell the system it is a float*
(you will not need the # when referencing the variable later)

--DESCRIPTION: [MY_NUMBER#=1.5(0.5,2.5)]
same as above but this time it will let you access a float number (set to 1.5) with a range from 0.5 to 2.5 (inclusive)

--DESCRIPTION: [THIS_IS_TRUE!=1]
this gives a tick box / toggle for if a variable is 1 or 0
*note the ! at the end, again this is required to tell the system it should be a true / false box
*note2 - not actually true or false in lua code but acts like it, the variable will be 1 if true (ticked) and 0 if false (unticked)

--DESCRIPTION: [@SELECTION=1(1=Item_1,2=Item_2)]
this one gives you a drop down selection box like when picked a weapon on the start marker etc
the part in brackets is broken up into 2 parts again - the left hand side being the index of the list and the right hand side being the name shown in the inspector
the actual value given in code is the index of the item selected
i.e. if you set SELECTION = "item_2" in the editor then in code the variable (selection) will be equal to 2

finally you can use any number of these together but you need to give them all unique names
i.e.
--DESCRIPTION: [MY_FIRST_NUMBER=1]
--DESCRIPTION: [MY_SECOND_NUMBER=10]
--DESCRIPTION: [MY_FIRST_FLOAT#=1.4]
--DESCRIPTION: [MY_FIRST_STRING$="Hello world"]
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 23rd Mar 2022 17:52 Edited at: 23rd Mar 2022 17:59
now as for actual usage, Max follows a specific naming convention where you will store the variables in an array / list based on the script name

first make a new lua file named
"my_first_script.lua"
*the name is important as we will use it for our list and our functions, if you rename the file you need to rename the core list variable and the function names otherwise Max will not call those functions!*

so we will start by defining a some dynamic lua to use


we now need to define an array to hold the values (this part can just go right below the --DESCRIPTION)


now we can make a properties(e) function
here we will pass in 'e' and the variable names we used in the DESCRIPTION (note that lower case is preferred here)


now we need an init(e) function where we will further set up the variable list
and we will also pass in some default values for the variables as we call the properties function manually
(Max will call it automatically but this makes the script work in GG Classic too)


now we need the main(e) function
this one is either adding or multiplying the first and second numbers together based on your selection


finally the whole code just for reference or those that want to skip ahead
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 23rd Mar 2022 22:44
Thank you smallg for that detailed explanation.
PM
synchromesh
Forum Support
10
Years of Service
Recently Online
Joined: 24th Jan 2014
Location:
Posted: 23rd Mar 2022 23:14
Excellent !!
What an awesome thread .

No one ever really leaves.
PM
42pixels
2
Years of Service
User Offline
Joined: 5th Nov 2021
Location: Hobart, Tasmania, Australia
Posted: 24th Mar 2022 01:14
This is brilliant! Thank you for the explanation
11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz 2.30 GHz, 32.0 GB, NVIDIA GeForce RTX 3060 Laptop GPU 6GB, Windows 10 Home 64bit, Screen resolution 1920 x 1080. System Passmark 3777
Guru
2
Years of Service
User Offline
Joined: 25th Mar 2022
Location:
Posted: 27th Mar 2022 09:00
Thank you for your tutorial here and the one on Steam guides. Been looking for a guide to get started in scripting
PM
mikeven
12
Years of Service
User Offline
Joined: 31st Dec 2011
Location:
Posted: 26th Apr 2022 22:13
Smallg, thank you for sharing the information relative to the available formats in the 'DESCRIPTION' comment.

Did you verify if the float numbers are working correctly in GameGuru MAX ?

Personally I noticed that there are systematically rounding errors with those numbers.

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Apr 2022 10:14
Quote: "Did you verify if the float numbers are working correctly in GameGuru MAX ?"

floats are not working in Max
i reported it when i made the tutorial, feel free to add a post there if you need working floats so it gets fixed sooner
https://github.com/TheGameCreators/GameGuruRepo/issues/2617
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
mikeven
12
Years of Service
User Offline
Joined: 31st Dec 2011
Location:
Posted: 27th Apr 2022 13:04
Smallg, thank you for your fast reply.

As suggested, I also posted a comment in your report on Github.

PM
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 26th May 2022 09:05
Thanks so much for this resource. I hope the dynamic lua options continues to grow.
Store Assets - Store Link
Free Assets - Resource Link

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960

Login to post a reply

Server time is: 2024-04-19 02:00:01
Your offset time is: 2024-04-19 02:00:01