Console help using 'local' [SOLVED]

Talk about anything related to Legend of Grimrock 2 here.
User avatar
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

Console help using 'local' [SOLVED]

Post by Frenchie »

Update : Now with help of minmay I got a better understanding and corrected my mistakes. My quotes are also corrected as they were typographic ones

In another topic the use of 'local' is used to create flintlocks with unlimited ammo:

Code: Select all

do local f = spawn(“flintlock”).firearmattack f:setClipSize(math.huge) f:setLoadedCount(math.huge) end
I wondered if I can use the syntax for a throw weapon with a higher attack power, but I didn't get it to have a stack:

Code: Select all

do local f = spawn(“shuriken”).throwattack f:setAttackPower(50) f:setStackSize(999) end
Normally you would use this:

Code: Select all

spawn("shuriken").item:setStackSize(999)
I could use this, but I wonder if it can be done in a better way:

Code: Select all

for i = 1,999 do local f = spawn(“shuriken”).throwattack f:setAttackPower(50) end end
This was solved by and evolved into :

Code: Select all

do local f = spawn("shuriken") f.throwattack:setAttackPower( 50 ) f.item:setWeight( 0.01 ) f.item:setStackSize(999) end
My second problem is I tried to shorten this:

Code: Select all

for i = 1, 4 do if party.party:getChampion( i ):getClass == “farmer” then party.party:getChampion( i ):addSkillPoints( 10 ) else party.party:getChampion( i ):addSkillPoints( 8 ) end
I thought that a condition that is true = 1 so this would work:

Code: Select all

for i = 1, 4 do party.party:getChampion( i ):addSkillPoints( 8 + ( party.party:getChampion( i ):getClass == “farmer” ) *2 ) end
With the use of local I tried:

Code: Select all

for i = 1, 4 do local ch = party.party:getChampion( i ) if ch:getClass == “farmer” then ch:addSkillPoints( 10 ) else ch:addSkillPoints( 8 ) end
Both combined working in :

Code: Select all

for i = 1,4 do local ch = party.party:getChampion( i ) ch:addSkillPoints( 78 + ( ch:getClass() == "farmer" and 2 or 0 ) ) end end
Last edited by Frenchie on Tue Jan 27, 2015 4:42 am, edited 10 times in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Console help using 'local'

Post by minmay »

All of these problems could have been resolved simply by consulting the scripting reference and/or Lua reference manual.
Frenchie wrote:I wondered if I can use the syntax for a throw weapon with a higher attack power, but I didn't get it to have a stack:

Code: Select all

do local f = spawn(“shuriken”).throwattack f:setAttackPower(50) f:setStackSize(999) end
This doesn't work because there is no ThrowAttackComponent:setStackSize() method. You wanted ItemComponent:setStackSize():

Code: Select all

do local f = spawn("shuriken") f.throwattack:setAttackPower(50) f.item:setStackSize(999) end
Frenchie wrote:My second problem is I tried to shorten this:

Code: Select all

for i = 1, 4 do if party.party:getChampion( i ):getClass == “farmer” then party.party:getChampion( i ):addSkillPoints( 10 ) else party.party:getChampion( i ):addSkillPoints( 8 ) end
I thought that a condition that is true = 1 so this would work:

Code: Select all

for i = 1, 4 do party.party:getChampion( i ):addSkillPoints( 8 + ( party.party:getChampion( i ):getClass == “farmer” ) *2 ) end
With the use of local I tried:

Code: Select all

for i = 1, 4 do local ch = party.party:getChampion( i ) if ch:getClass == “farmer” then ch:addSkillPoints( 10 ) else ch:addSkillPoints( 8 ) end
But all both attempts failed
This doesn't work because:
1. A condition that is true doesn't equal 1. It equals true.
2. "party.party:getChampion(i):getClass" is invalid syntax. Function calls must be denoted by parentheses, as in "party.party:getChampion(i):getClass()".
You wanted:

Code: Select all

for i = 1,4 do party.party:getChampion(i):addSkillPoints(8+(party.party:getChampion(i):getClass() == "farmer" and 2 or 0)) end
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.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Console help using 'local'

Post by Azel »

In the world of boolean logic, True = 1 and False = 0, however, in LUA and other languages (both scripting and compiled), you can't really make these assumptions. At least not without doing a conversion.

I had to learn LUA in order to create my first Mod, and the biggest thing that caused me a headache is the NOT EQUAL TO notation. I always use "!=" but LUA demands "~=" :o

Concatenation in LUA is annoying as well. Da fuk is " .. " for concatenation? Either "+" or "&" ... should be universal. hmph

Pain in ma' arse!!
User avatar
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

Re: Console help using 'local'

Post by Frenchie »

All of these problems could have been resolved simply by consulting the scripting reference and/or Lua reference manual.
Not all of us find it simple or are well-versed in Lua. I did look at the reference, but I can't understand everything. I see someone's script, modify and add to it and see what happens. I didn't write all my attempts here, but the most logical ones.
do local f = spawn("shuriken") f.throwattack:setAttackPower(50) f.item:setStackSize(999) end
I tried this but I might have made a typo somewhere. Thanks for clearing it up. I wanted to lessen the weight by adding f:setWeight(0.01) or f:item.setWeight(0.01) but both are not accepted. The reference says the variable is in kg.
In the world of boolean logic, True = 1 and False = 0,
For me this is edged into my brain. Many many years ago I learned some programming. Azel, if there's a good link with all the headaches let me know.
for i = 1,4 do party.party:getChampion(i):addSkillPoints(8+(party.party:getChampion(i):getClass() == "farmer" and 2 or 0)) end
My brain is struggling with the use of 'and' after "farmer". I would expect a 'then' in the 'if then else' syntax.
Last edited by Frenchie on Sun Jan 25, 2015 2:58 pm, edited 4 times in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Console help using 'local'

Post by minmay »

Boolean true and false have their own type in Lua, separate from numbers.
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
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

Re: Console help using 'local'

Post by Frenchie »

for i = 1, 4 do local ch = party.party:getChampion( i ) if ch:getClass == “farmer” then ch:addSkillPoints( 80 ) else ch:addSkillPoints( 78 ) end
I can't use local to shorten syntax like the above?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Console help using 'local'

Post by minmay »

You can. What you can't do is leave a block unclosed and expect the interpreter to be OK with it. You need to close both your for loop and your if statement; you're only closing one. And again, ch:getClass == "farmer" is invalid syntax. You have to have parentheses to call a function. This is not optional. Here is what you wanted:

Code: Select all

for i = 1, 4 do local ch = party.party:getChampion(i) if ch:getClass() == "farmer" then ch:addSkillPoints(80) else ch:addSkillPoints(78) end end
edit: replaced quotes for you too
Last edited by minmay on Sun Jan 25, 2015 9:20 pm, edited 1 time in total.
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
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

Re: Console help using 'local'

Post by Frenchie »

Thanks for the correction. I was meant to add the () and forgot about the extra end. This new knowledge will shorten existing functions I have.

So the shortest version would be:

Code: Select all

for i = 1,4 do local ch = party.party:getChampion( i ) ch:addSkillPoints( 78 + ( ch:getClass() == “farmer” and 2 or 0 ) ) end end
As for the shuriken I added weight correctly:

Code: Select all

do local f = spawn("shuriken") f.throwattack:setAttackPower(100) f.item:setWeight( 0.01 ) f.item:setStackSize(999) end
Is there also a way to copy quotes " " into the console?
Last edited by Frenchie on Sun Jan 25, 2015 9:13 pm, edited 1 time in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Console help using 'local' [almost SOLVED]

Post by minmay »

You need to use "" not “”.
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
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

Re: Console help using 'local' [almost SOLVED]

Post by Frenchie »

I can't copy any code containing " " quotes. I have to remove them for pasting to work. Then manually add them again after pasting the quote-less code
Post Reply