Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Multidimension array as a local?

Author
Message
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 2nd Jun 2019 17:47 Edited at: 2nd Jun 2019 17:58
I can't figure out how to set up a multidimensional array as a type without the keyword dim. I am getting an error that "this must be a literal integer".

Is this possible?

This works, but I would really like to not make this a global array.


This doesn't


edit: These are defined as integers



Thanks!
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jun 2019 21:27
global pf_Node[nx,nz] as pf_grid
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 2nd Jun 2019 22:35
But that makes it a global. I just want it to be local.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Jun 2019 23:51
You would need to initialize it with a literal and then use the .length property to st the length like this;


If you are initializing it from data you might do something like this

Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jun 2019 00:06 Edited at: 3rd Jun 2019 00:09
Ah, wow.. that is cumbersome. Thank you, Blink0k, I will have to do that! Creative way to make it happen.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jun 2019 00:27
Sorry Golelorn I mis read but if you replace the word global with local its should work
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jun 2019 00:34 Edited at: 3rd Jun 2019 00:37
fubar, neither global nor local work. I get an error message of "unexpected token [". Only Dim works with that syntax.

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jun 2019 02:29 Edited at: 3rd Jun 2019 02:38
local pf_node as Node[nx, nz]

Although i don't think it accepts variables as dimension values

It's very odd behavior because if i define the dimension values in the main proggy it works


But if i remove the definitions from the main proggy it fails.

Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jun 2019 02:56 Edited at: 3rd Jun 2019 02:57
It will not accept variables, which I need it to do, since my maps could be different sizes.

I noticed there is a lot of odd behavior when trying this. Sadly, I think the only way is the "hack" you have shown, earlier.

And again, I do not want to use dim or globals, because that will be a very large array. (Maybe that doesn't matter? I thought fubarpk showed previously that large globals impact performance).
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jun 2019 03:03
If it's a map of some sort i would consider using a .json file and then it will be very easy to load
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jun 2019 03:12
Eh, it only take a few seconds to build it out. I think I like your earlier hack better ¯\_(ツ)_/¯
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jun 2019 03:18 Edited at: 3rd Jun 2019 03:19
Sorry I got mixed up but is it possible that you do something like


json is also an option
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jun 2019 03:18
If you have a proggy that creates the level data then all you need to do is save that array to a json file : MyArray.save("level.json")
Then in this program load it in using : MyArray.load("level.json")
So easy
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jun 2019 03:21 Edited at: 3rd Jun 2019 03:22
if you use types like I showed above you could use mytypes.length to get the number of nodes in the array
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jun 2019 03:21
Its a Navmesh, blink0k. I do use json to load levels.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jun 2019 03:23
If you use .json, how come you need to pre-define the array size?
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jun 2019 03:24 Edited at: 3rd Jun 2019 03:28
a type can also be defined like


or even
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jun 2019 03:42 Edited at: 3rd Jun 2019 03:55
Blink0k,

I think I am misunderstanding you. I load in my land objects and then the "decor" objects via json. The Navmesh takes how big the loaded area is, and then adds four Nodes per 1x1 area. Some of my areas are different sizes. Otherwise, I would just use a literal number. I don't see how the two are interchangeable. As, I could change the amount of nodes in an area if I felt I needed more for better realism.

I think we are losing sight of the original question which is why can I not create a local multidimensional type array, but I can create a dim multidimensional type array.

edit for misspellings
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jun 2019 03:57 Edited at: 3rd Jun 2019 03:58
I think you've both shown good hacks to overcome this, and I do really appreciate it(i totally failed at seeing those). But, it sorta feels like a bug when one declaration works and another fails.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jun 2019 04:15
the advantage of not declaring the array really is allot more useful when you get the hang of it as you can constantly change it
the disadvantage it can get a little confusing with multidimensional arrays. The ability to pop and push etc in the array is also
handy this way. Not sure the code behind dim as to why that allows variables and types need to be constants or [] you could also
declare as [0,0] but you still need to use insert. So that isn't that useful. If they are already saved as json blinks method is prob the
most useful. but id you have one global dim statement that shouldn't hurt too much and im sure theres a way of dimming that
is exactly what you want I just cant for the life of me think of the syntax I thought you just needed to added local or global to it
but then I refrain from the dim method anyway I think it converts badly
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jun 2019 04:20
Ok no worries Golelorn. Good luck with your project matey

Login to post a reply

Server time is: 2024-04-24 03:05:15
Your offset time is: 2024-04-24 03:05:15