Page 1 of 1

[Scripting] - Array of arrays not possible ?

Posted: Sun Nov 02, 2014 10:39 pm
by Blichew
Hi there,

so I've been trying to store some values within array that consists of multiple arrays, like that:

Code: Select all

dest = {1 = { 1, 25, 12, 0},
		2 = { 1, 27, 12, 0}}
But this doesn't seem possible within Grimrock Editor. I keep getting this error:

Image
Or I'm just doing something wrong ?

Re: [Scripting] - Array of arrays not possible ?

Posted: Sun Nov 02, 2014 10:50 pm
by NutJob
just do:

Code: Select all

local a= {
	{1,2,3,4},
	{5,6,7,8}
}
if you're using numerical keys.

Associative works, so long as it's not what it numerical key would of been

So,

Code: Select all

local a= {
	red = {1,2,3,4},
	fish = {5,6,7,8}
}
is fine, too.


---


If you need to reorder an assoc.table this may be helpful and I got something similar to this working.

Re: [Scripting] - Array of arrays not possible ?

Posted: Sun Nov 02, 2014 11:07 pm
by Blichew
Thanks :) I forgot about the fact that
Associative works, so long as it's not what it numerical key would of been
:)

Re: [Scripting] - Array of arrays not possible ?

Posted: Sun Nov 02, 2014 11:38 pm
by cameronC
This is something I was trying out without much success and this has helped. So, I print(a.fish[3]) and it prints out 7.

How can I change it so a variable is used to determine what secondary values to pull from? Say, this is in a function that will be passed "red" or "fish" and I want to use that value as the secondary lookup in a?

Re: [Scripting] - Array of arrays not possible ?

Posted: Mon Nov 03, 2014 12:26 am
by Jouki
Blichew wrote:Thanks :) I forgot about the fact that
Associative works, so long as it's not what it numerical key would of been
:)
OT: I guess it's for your teleporter scroll, isn't it? :D becasue it was first thing in my mind when I read your post about that :lol:

Re: [Scripting] - Array of arrays not possible ?

Posted: Mon Nov 03, 2014 12:53 am
by Blichew
Yeah, that why I was asking, it would be easier to define new teleporter scrolls :)
I think it's still readable in it's current form thou - maybe not so efficient (scripting-wise)...

Code: Select all

teleport_scroll_targets = {"teleport_scroll_1",1,25,12,0, -- {scrollID,level,X,Y,elevation}
                     "teleport_scroll_2",1,27,12,0}

Re: [Scripting] - Array of arrays not possible ?

Posted: Mon Nov 03, 2014 3:29 am
by Zanzer
Did you figure it out, or did you want something like:

Code: Select all

dest = {
  ["red"] = { 1, 25, 12, 0},
  ["fish"] = {1, 27, 12, 0}
}

Re: [Scripting] - Array of arrays not possible ?

Posted: Mon Nov 03, 2014 3:34 am
by Blichew
I left it the way it is for now:

Code: Select all

teleport_scroll_targets = {"teleport_scroll_1",1,25,12,0, -- {scrollID,level,X,Y,elevation}
                     "teleport_scroll_2",1,27,12,0}
and I just run for i=1,#teleport_scroll_targets. If value == teleport_scroll_x then it's params are like teleport_scroll_targets[i+1], teleport_scroll_targets[i+2] and so on.

I'll probably get back to it as soon as I find a while to clean up my scripts.

Thanks,
Blichew

Re: [Scripting] - Array of arrays not possible ?

Posted: Mon Nov 03, 2014 11:40 am
by Leki
For my dialog system I have this structure (simplified) and it works well, so you can adopt it I guess:

Code: Select all

dialogs = {
  npc01 = {
    line01 = {text = "Sentance 01.", dialog = "npc02"},
    line02 = {text = "Sentance 02.", dialog = "npc02"},
    line03 = {text = "Sentance 03.", dialog = "npc02"}
  },  

  npc02 = {
    line01 = {text = "Sentance 01.", dialog = "npc01"},
    line02 = {text = "Sentance 02.", dialog = "npc01"},
    line03 = {text = "Sentance 03.", dialog = "npc01"}
  }  
}