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.

AppGameKit Classic Chat / insert record into array with type

Author
Message
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 31st Aug 2015 12:06
Hi,
This may be an incredibly simple and obvious thing, but, how do you insert a new record into a blank array that has been declared as a type?

I know that inserting into a normal blank array is done as follows.

myarray.insert(data)

but I cannot find how to insert into a type declared array eg
myarray.typefield.insert(data)
or
myarray.insert.typefield(data)

How do you do this? I cant find anything in the help files and not a lot relevant comes up when I search the forum.

Thanks,
Kezzla

To Err is Human...
To Arr is Pirate!
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 31st Aug 2015 12:11
Whoops! Wrong forum.

Can a mod please move this to the AppGameKit forum?

Cheers

To Err is Human...
To Arr is Pirate!
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 31st Aug 2015 12:29 Edited at: 31st Aug 2015 12:30
Can you insert an array into a type? I don't think that's possible. Arrays in types. It was my feature request back in the day, and it was denied as too advanced of a concept. Contact me via email if you need further assistance. Or are you just trying to do this:

myarray(id).typefield.insert(data)

Not sure if this is possible. Arrays and types do not go well together.

Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 31st Aug 2015 18:25 Edited at: 31st Aug 2015 18:27
without knowing anything about agk won't you need to insert an entire array element, with all attached type data?

generally you can't just extend arrays by a single property, you add a whole index with all properties (even if the values are set to null)

myarray.insert()
myarray().typefield = data

does myarray.insert(data) fail if data is itself declared as the same type as the array instead of a singular value?

myarray as mytype
data as mytype

data.typefield = somevalue
data.typefieldB = somestring

myarray.insert(data)

Yodaman Jer
User Banned
Posted: 1st Sep 2015 03:45
Ah yes Ortu, that is the correct way to go about it! +1111111, and a coffee!

Or a beer, that works too.


Forum President until June 20th, 2016.
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 1st Sep 2015 13:29
Thanks guys,

I should clarify,
I want to make an array of objects and have their properties stored using a type.

I want the array to be dynamic, however as soon as i declare the array as a user defined type I cannot find a way to insert a new element into an array
Quote: "
Or are you just trying to do this:

myarray(id).typefield.insert(data)"


yeah that is almost what I am trying to do but rather than defining the variable id, I would like a new element inserted at the end.

ok guys, now I am starting to get the lingo, basically I want a dynamic array declared as a type.

Quote: "generally you can't just extend arrays by a single property, you add a whole index with all properties (even if the values are set to null)

myarray.insert()
myarray().typefield = data"


this is what I want to do but I get the error unexpected token, among other errors for different attempted variations of the command.

....

Quote: "does myarray.insert(data) fail if data is itself declared as the same type as the array instead of a singular value?

myarray as mytype
data as mytype

data.typefield = somevalue
data.typefieldB = somestring

myarray.insert(data)"

Thanks Ortu!
We have a winner! Maybe I should have skipped to the end of the thread

Thanks for that mate, that seemed to do the trick in a quick test.
I wont be coding tonight, so I will check back in with results later on.

It seems as though this is something to maybe add to the featurecreep thread so that we don't have to declare a dummy variable as a type in order to expand a dynamic array declared as a type.(marathon sentence).

Thanks all for chipping in.


To Err is Human...
To Arr is Pirate!
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 1st Sep 2015 14:18 Edited at: 1st Sep 2015 14:32
This isn't something to add to the features. It is normal and expected behaviour.

Let me try to explain in real world terms instead of code:

Imagine you work on a market stall selling only fruit baskets. Each basket contains a number of apples, bananas and oranges. You check your inventory and see that you have 10 fruit baskets and then the delivery boy arrives with another.
You look inside and see that it also contains apples, bananas and oranges and so it can be added directly in to your inventory (inserted into your array).

Then you notice that you have some loose fruit. An apple, two bananas and three oranges. You want to insert those into your inventory too but you can't insert them as before because the inventory only contains a list of fruit baskets not loose fruit.
So you have two options:
1) You can add the loose fruit to already existing fruit baskets.
2) You can put them in a new basket and then insert that into your inventory.

And that scenario in code:


AGK V2 user - Tier 1 (mostly)
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 1st Sep 2015 15:10 Edited at: 1st Sep 2015 15:11
Your example makes sense Scraggle, However my thought was that It would be nice to be able to create a new element without having to specify a full set of data. to use your example, add an empty basket that we can then put fruit in when it suits us put it in there.

however on more thought, perhaps I can just use a temp variable declared as a type to hold all the data and then import it at the end of the function.

hmmm, I will give that way a go. It didn't occur to me to work that way.

Thanks mate.

To Err is Human...
To Arr is Pirate!
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 1st Sep 2015 15:19 Edited at: 1st Sep 2015 15:33
Yes, That is exactly what I did in the example.

Both deliveredFruitBasket and newFruitBasket are temporary variables which I then populated with data (fruit) and inserted into the array.
Once they are in the array they can be deleted or forgotten about.

Quote: "to use your example, add an empty basket that we can then put fruit in when it suits us put it in there"



There's your empty fruit basket

And here I am putting a bunch of bananas in it:


AGK V2 user - Tier 1 (mostly)
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 1st Sep 2015 15:35
true that, I feel like my mum learning that the folder on the desktop is the same folder I am showing her in windows explorer.

I will get there in the end. Thanks Scraggle.

To Err is Human...
To Arr is Pirate!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Sep 2015 15:59 Edited at: 1st Sep 2015 22:06
something like this?
basketlist[x].fruitlist[x].name



AGK (Steam) V2 Beta .. : Windows 10 Pro, 8.1 Pro 64 Bit : AMD (15.7.1) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 3rd Sep 2015 13:00
Ah yes I see this made it into AppGameKit 2: https://code.google.com/p/agk/issues/detail?id=62

I don't use AppGameKit anymore so sorry for the outdated info!

Login to post a reply

Server time is: 2024-11-16 20:56:35
Your offset time is: 2024-11-16 20:56:35