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 / track the size of array by variable

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 31st Mar 2015 15:28
Hi.

In AppGameKit v2 for insert or remove array elements we can use:



and for get array length we can use myArray.length.

But I have AppGameKit v1 and I need Insert and remove array element and track the size of array by variable.but I don't know how to do it.

Please Guide Me.

Thanks.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 31st Mar 2015 15:41
Hi

Ok, I would create an array like this:

Then to add an item:

Then to delete an item during a for/next:


Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 31st Mar 2015 15:52 Edited at: 31st Mar 2015 15:54
Thanks baxslash I understood

but for create bullet there is another way that we don't use insert or remove elemnts in array?

UPDATE: I think for do it should create User Data Type. can you give an bullet example with User Data Type that learn how can use it in Programming?

Thanks.
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 31st Mar 2015 16:06 Edited at: 31st Mar 2015 16:14
Quote: "but for create bullet there is another way that we don't use insert or remove elemnts in array?"


Yes, you could create an array upfront with enough slots to hold the max amount of bullets you require. And then just cycle through them all...

Like so (this is psuedo code, untested, and unlikely to work out the box... But should give you the idea...);



EDIT

Quote: "UPDATE: I think for do it should create User Data Type."


Yes, Data Types would be a better solution, but in my opinion, more complex... I've only just started using Data Types myself, took me a while to work em out

EDIT2

In my example above, it is possible that the user could button bash fire more than 50 times before the first bullet gets a chance to be deleted... Easily resolved, but will let you work that out

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 31st Mar 2015 16:22
Thanks Funnell7.

very useful example.
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 2nd Apr 2015 15:33
This is what I am doing for bullets. Unless the bullets last for a long time the array doesn't have to be that large so it's not an issue. It gets slightly more complex if you want bullets to last for different amount of time as you develop 'bubbles' in the array which decreases you ability to shoot.

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)

Login to post a reply

Server time is: 2024-11-21 16:38:23
Your offset time is: 2024-11-21 16:38:23