2-Dimensional variables [SOLVED]

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!
Post Reply
User avatar
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

2-Dimensional variables [SOLVED]

Post 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.
Last edited by Frenchie on Wed Jan 14, 2015 5:36 am, edited 7 times in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: 2-Dimensional variables

Post 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
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: 2-Dimensional variables

Post 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.
Last edited by Frenchie on Tue Jan 13, 2015 10:49 am, edited 3 times in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: 2-Dimensional variables

Post by minmay »

The code you have in your post works fine for me. What error message are you getting?
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: 2-Dimensional variables

Post 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 '='
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: 2-Dimensional variables

Post by Isaac »

Is there a reason it has to work in the console? [not everything does]
User avatar
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

Re: 2-Dimensional variables

Post 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.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: 2-Dimensional variables

Post by Isaac »

Code: Select all

  a = {"alchemy", "firearms", "light_weapons"} for each = 1, #a do 	print(a[each]) end
User avatar
Frenchie
Posts: 219
Joined: Wed Oct 16, 2013 2:50 am

Re: 2-Dimensional variables

Post by Frenchie »

Thx, that worked! Now, my only wish is to make the console font 2x as big...
Post Reply