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 / Create object using array type and keep track of it?

Author
Message
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 20th Feb 2018 04:43 Edited at: 20th Feb 2018 04:44
Ok, im just try to understand array of type a bit more.
Let say i want to create an object type and i dont wish to know its initial size e.g object as objectyltype[10]

Let say i just use object as objectype(non array). Is they any way i can check the size later on or try to iterate thru all of ot later.

Thanks
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 20th Feb 2018 05:40 Edited at: 20th Feb 2018 05:45
UDT arrays use the same principles as basic arrays. you don't have to initialize them to a size. you can .insert as needed. you can check the size and iterate using .length

http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 20th Feb 2018 07:51
Ok...now i get it...im quite confuse with the type name and the list name..TQVM
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 28th Feb 2018 20:25
If you are going to make such a list, it would also be a very useful thing to store the object ID, because things like raycasting return the ID number, not the .name or .number property.
I use a quick check that loops through a list and checks if object_hit from a raycast is equal to the myObject.ID and from there I can manipulate further. If you don't store the ID, it is pretty darn difficult to do much with the object, unless you're building something that operates entirely from the data based values only I guess.
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 1st Mar 2018 00:49
ok...back to basic.

dim test[]<---no size

i found that we cannot assign something in it using test[0]=value,test[1]=value2. This is true right? i use insert command but just to confirm.

Thanks
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 1st Mar 2018 17:26
It's a bit hidden in the manual but if you go to Guides -> General - Arrays in version 2 , then you do get to see basically all of the syntax for arrays usage.

As for multidimensional arrays, I tend to fill my types with an array I created before storing them in a type (although you can do this straight away I think, not exactly sure). Unless you have a different intention for how to use multidimensional arrays, I would look at the part in the guides section and Arrays in version 2 that talks about 'subarrays'. Also take a good look at the example already in this thread about myObjectlist and adding objects to that. It kind of shows all you need to know in order to use them.

PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 1st Mar 2018 23:37
Yeah, that works indeed, however you can totally use 'empty' arrays too, like this:

Quote: "myObjectList as myObjectData[]"


The myObjectList still starts out as a completely empty array and with the type example given by Ortu it is easy to fill the array afterwards. I guess this was moreso Hoyoyo80's question, but you can have arrays that start out 0 initially.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Mar 2018 15:15
Keep in mind, if you create an empty array then insert into it, your first element will be at 0.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Mar 2018 19:10
And rather than using loops to find your object_id, use the .find() array function, its far quicker when you havelots of objects.

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 2nd Mar 2018 19:17
Multidim , isnt like that ?

Dim foo as footype [-1,-1]

I'm not sur
AGK2 tier1 - http://www.dracaena-studio.com
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Mar 2018 19:31
You can not have a multidimension type, but yes for defining empty MD arrays you use -1

Dim arr[-1,-1]
or
Global arr as string[-1,-1]
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 3rd Mar 2018 15:40 Edited at: 3rd Mar 2018 15:41
Quote: "You can not have a multidimension type, but yes for defining empty MD arrays you use -1"


Maybe not literally, however doesn't that depend a bit on how you structure your data attached to it???

You can assign types to types and you can fill types with data arrays of any dimension or size.

edit: I should probably ask what the intentions are of using a multidimensional array for a more specific answer.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Mar 2018 14:54
Quote: "You can not have a multidimension type,"


You sure? Because I'm pretty certain I've stored 2D grid-based maps that way.

map as MapData[][]
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-23 00:43:24
Your offset time is: 2024-11-23 00:43:24