Page 1 of 2

Console help using 'local' [SOLVED]

Posted: Fri Jan 23, 2015 11:33 am
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

Re: Console help using 'local'

Posted: Fri Jan 23, 2015 7:43 pm
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

Re: Console help using 'local'

Posted: Fri Jan 23, 2015 8:48 pm
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!!

Re: Console help using 'local'

Posted: Sat Jan 24, 2015 5:02 am
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.

Re: Console help using 'local'

Posted: Sat Jan 24, 2015 5:13 am
by minmay
Boolean true and false have their own type in Lua, separate from numbers.

Re: Console help using 'local'

Posted: Sun Jan 25, 2015 2:59 pm
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?

Re: Console help using 'local'

Posted: Sun Jan 25, 2015 7:59 pm
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

Re: Console help using 'local'

Posted: Sun Jan 25, 2015 8:48 pm
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?

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

Posted: Sun Jan 25, 2015 9:11 pm
by minmay
You need to use "" not “”.

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

Posted: Sun Jan 25, 2015 9:19 pm
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