[Scripting] - Array of arrays not possible ?

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
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

[Scripting] - Array of arrays not possible ?

Post 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 ?
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

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

Post 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.
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

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

Post by Blichew »

Thanks :) I forgot about the fact that
Associative works, so long as it's not what it numerical key would of been
:)
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

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

Post 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?
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

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

Post 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:
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

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

Post 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}
Zanzer
Posts: 8
Joined: Sun Nov 02, 2014 4:38 pm

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

Post 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}
}
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

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

Post 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
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

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

Post 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"}
  }  
}
I'm the Gate I'm the Key.
Dawn of Lore
Post Reply