another question about syntax

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

another question about syntax

Post by FeMaiden »

again, i'm in the monster definitons and i noticed this

many monsters have resistanes and immunities to certain elements.

most of them have it notated like this

Code: Select all


resistances = {
				fire = "immune",
				cold = "immune",
				poison = "immune",
				shock = "absorb",
				physical = "immune"
			},

but then the skeleton commander has it listed like this

Code: Select all


resistances = {
				["poison"] = "immune",
				["shock"] = "weak",
			},

why is it in brackets? is this like the semicolon question I asked about before? it something that you Can do but you don't have to?

and then i look at ice lizard and it has

Code: Select all


immunities = { "cold" },

is this a vestigial code left over from grimrock 1? since the ice lizard does not appear in gromrock 2, they never bothered to change it?

it seems like we need to say resistance cold = "immune"
in all the other monster definitions
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: another question about syntax

Post by THOM »

I have no idea about the bracket question.

But monsters in LoG2 can have immunies and resistances.

Here are some stats you can give

Code: Select all

* resistances =
fire
poison
shock
cold
physical
dispel 

* levels for "resistances" =
weak
vulnerable	
resist
immune
absorb


* traits =
animal
undead
elemental

* immunities =
sleep
blinded
frozen
stunned
knockback
backstab
poison
burning
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: another question about syntax

Post by Azel »

Some of these questions can be answered with a simple Google Search:

https://en.wikipedia.org/wiki/Help:Lua_for_beginners
http://lua-users.org/wiki/StringsTutorial
There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:

a = {[0] = 'zero', [1] = 'one', ['1'] = 'string for one'}
the string "3377" is the content of frame.args[1] (which is the same as frame["args"][1] but not frame.args["1"] or frame["args"]["1"]) Unnamed parameters come out as numbers, while named parameters come out indexed as strings.
I see no reason for the developers to "clean up" every single variation of syntax (using "string" vs [[string]] vs ["string"]) since the end-goal here to make a video game that people can actually enjoy. That should be your main focus: your gaming deliverable.
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: another question about syntax

Post by FeMaiden »

I wasn't trying to be anal about grammar.
I was merely trying to understan why certain things do and do not work in lua.

if it's understood that I can do it with or without the brackets, just like with the semicolons then i can let the matter close.


but then I see the other thing.

there is

the one code for resistances cold = immune

and then there is
immunities = ( "cold" )

would either one work? or is the immunities = ( "cold" ), the way it was done in grimrock 1?
the ice lizard is the only monster that lists the elemental immunities unter immunities and all the other monsters list the elemental immunity under resistances
and yeah I guess this question could have been resolved easily if I just experimented with it in custom monster definitions.

I was just somewhat reluctant to be adding lines of code with inconsistent syntax into a mod that is 99% complete with the risk of catastrophically breaking my mod.

I'm almost ready to export it and start testing through the main game engine
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: another question about syntax

Post by minmay »

Resistances are resistances to damage types and are always formatted as a table with the damage types as keys and the level of resistance as the corresponding value. E.g.:

Code: Select all

resistances = {
  physical = "immune",
  cold = "resist",
  fire = "weak",
}
Note: There are infinite possible damage types, you can actually set a weapon's damage type to "chili dogs" and it will work. The builtin damage types have special effects however (like flames appearing on the monster's body for fire damage, and all the special handling for dispel damage).
Immunities are immunities to status effects and are not related to resistances in any way. They are formatted as an array of the names of the status effects, e.g.

Code: Select all

immunities = {"frozen","stunned"}
Stop trying to copy and paste Grimrock 1 code into Grimrock 2! It won't work! The component system is different from the way things are handled in Grimrock 1.

In Lua, inside a table definition,

Code: Select all

["cow"] = 1
is equivalent to

Code: Select all

cow = 1
Similarly, when indexing a table,

Code: Select all

table["cow"]
is equivalent to

Code: Select all

table.cow
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: another question about syntax

Post by FeMaiden »

okay, I get it.


for the record, I wasn't trying to copy paste grimrock 1 code into grimrock 2 definitions.

minor spoiler
I have a custom skeleton commander in my mod. I changed some of his stats around.
I saw they have his resistances in the brackets. listed like this

Code: Select all


resistances = {
				["poison"] = "immune",
				["shock"] = "weak",
			},


I just changed what is between the brackets to say a different element so instead of being weak against shock he is weak against something else.
he works perfectly.

where the confusion arose is that none of the other monsters use the brackets in their definitions.

so if I decided that I want to give my skeleton commander more resistances, should I stay consistent and keep using the brackets on every line?

so

Code: Select all


 poison = "immune",

--and 

["poison"] = "immune",

are both acceptable?
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: another question about syntax

Post by FeMaiden »

never mind, I think i'm just drawing you guys into a "who's on first" loop.

it's anxiety because I never actually *finished* a project before.

and now i'm just hyping people up and I didn't mean to do that
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: another question about syntax

Post by Azel »

Yeah it gets pretty confusing because you bring Grimrock 1 up at times during your analysis, which is basically an apples/oranges comparison.

Also, I would recommend just testing things out for yourself before posting on the Forums. I spent almost an equal amount of time testing things as I did actually building my Mod. Often times I spent more time testing a single concept than I spent implementing it.

For example, I spent some 6+ hours testing out different approaches to "underwater breathing" and in the end I spent maybe 45 minutes writing the actual code that uses this feature.

Another thing to consider (I took this advice myself) is that excess testing helps you become more familiar with the modding framework, which will increase your chance of successfully finishing a project that people will play. In contrast, if you spend too much time posting question after question with spoiler after spoiler on the forums... then that ends up becoming your Mods "marketing material." No one wants bad marketing, right? lol
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: another question about syntax

Post by Isaac »

minmay wrote:In Lua, inside a table definition,

Code: Select all

["cow"] = 1
is equivalent to

Code: Select all

cow = 1
Similarly, when indexing a table,

Code: Select all

table["cow"]
is equivalent to

Code: Select all

table.cow
And for those (new to it) that do not know the useful distinction here...

table["cow"] accepts the string "cow", but it accepts variables that have string values. It will even accept a table of strings and/or numbers; provided the values exist in it.

Code: Select all

animal = {'cow', 'duck', 'frog'}
table = {['cow'] = 'moo', ['duck'] = 'quack', ['frog'] = 'ribbet'}
for x = 1, #animals do
print('A '..animal[x]..' goes \"'..table[animal[x]]..'\".')
end
A cow goes "moo".
A duck goes "quack".
A frog goes "ribbet".
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: another question about syntax

Post by minmay »

FeMaiden wrote:so if I decided that I want to give my skeleton commander more resistances, should I stay consistent and keep using the brackets on every line?

so

Code: Select all


 poison = "immune",

--and 

["poison"] = "immune",

are both acceptable?
Again, there is no difference. Both are exactly the same.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply