Page 1 of 1

2-Dimensional variables [SOLVED]

Posted: Tue Jan 13, 2015 10:02 am
by Frenchie
I want to use the variables a(1) to a(8) and b(1) to b(8) in the console line, but I keep failing:

Code: Select all

a[1]="alchemy" a[2]="firearms" ect.
b[1]=5 b[2]=3 etc.
for ii=1,8 do for i=1,4 do party.party:getChampion(i):trainSkill(a[ii],b[ii]) end end

a={[1]="alchemy", [2]="firearms" etc.}
b={[1]=5, [2]=3 etc.}
for ii=1,8 do for i=1,4 do party.party:getChampion(i):trainSkill(a[ii],b[ii]) end end
Or do something similar with setBaseStat.

Is it possible to use 2-dimensional variables like this?

UPDATED: Thanks the below comments the format should be

Code: Select all

a={"alchemy","firearms" etc.} and b={5,3 etc.}
I have an idea for a puzzle as follows:
There are 2 patchs to choose. The left one looks very dangerous with lots ranged mobs that can't get in melee range. The right looks easy with a few melee mobs. Depending on your decision I want to change either skills or stats (not sure right now what works best). So, first I read and store your skill/stat level. Then I either boost (right path) or decrease (easy path) them. If you survive I give your original skill/stat level back. If you choose the 'right' path, which would be the hard looking one, you gain 2 skill/stat points. But if you took the 'easy' path I would randomly decrease 2 skill/stats -1. Basically you are blessed or cursed. But you can redeem yourself by placing a valuable item in an alcove to get the decrease undone.

How everything is scripted exactly might be a different topic discussion. With 2-dimensional variables it makes it easier.

Re: 2-Dimensional variables

Posted: Tue Jan 13, 2015 10:13 am
by minmay
PartyComponent.getChampion is a function. You pass it a number and it returns the champion at that index. The code you wanted is:

Code: Select all

for ii=1,8 do for i=1,4 do party.party:getChampion(i):trainSkill(a[ii],b[ii]) end end

Re: 2-Dimensional variables

Posted: Tue Jan 13, 2015 10:25 am
by Frenchie
I made a typo with Champion(i) and corrected it but that's not the problem. The console doesn't accept my 2-dimensional variables and gives an error after =

Of course I could do something like the following:

Code: Select all

function train(i,ii) party.party:getChampion(i):trainSkill(ii,5) end
ii="alchemy" for 1,4 do train(i,ii) end
ii="firearms" for 1,4 do train(i,ii) end
etc.
But if it can be done better with 2-dimensional variables I would prefer that.

Re: 2-Dimensional variables

Posted: Tue Jan 13, 2015 10:36 am
by minmay
The code you have in your post works fine for me. What error message are you getting?

Re: 2-Dimensional variables

Posted: Tue Jan 13, 2015 10:46 am
by Frenchie
When I type:

Code: Select all

 a[1]="alchemy" -> [string "user-input"]:1: attempt to index global 'a' (a nil value)

a={[1]="alchemy",[2]="firearms"} -> [string "user-input"]:1: ')' expected near '='

Re: 2-Dimensional variables

Posted: Tue Jan 13, 2015 10:56 am
by Isaac
Is there a reason it has to work in the console? [not everything does]

Re: 2-Dimensional variables

Posted: Tue Jan 13, 2015 10:58 am
by Frenchie
I haven't made any custom dungeon, but when I get an idea I test it in the console. When successful I add it to my LoG2 ideas.txt. When you know something works it brings up more ideas.

Re: 2-Dimensional variables

Posted: Tue Jan 13, 2015 11:06 am
by Isaac

Code: Select all

  a = {"alchemy", "firearms", "light_weapons"} for each = 1, #a do 	print(a[each]) end

Re: 2-Dimensional variables

Posted: Wed Jan 14, 2015 5:29 am
by Frenchie
Thx, that worked! Now, my only wish is to make the console font 2x as big...