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 / Arrays in AGK2

Years of Service
User Offline
Joined: 10th Feb 2015
Posted: 10th Feb 2015 22:28
just messing about in AGK2 trying to get to grips... and I only have Python as a reference.. so in Python, when you want to append to an array you get use, for example:

x, y = pygame.mouse.get_pos()
my_array.append([x, y])

is there a way to append values in AGK2?
Also, can the array store tuples (as per the above python example) ?
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 11th Feb 2015 08:47
AGK2 is a much more limited core language than Python.

It has floats, integers, strings, arrays and types. arrays are like lists, types are a structure of named data. Python does not have this, types are like a hash but where the keys are predefined. The whole system is static.

It helps if you are old Older coders like me are used to programming without objects. If you've been trained to program in OOP you have to rethink a bit, in AppGameKit you can't do it.

So you might write something like.

To define a structure of mouse positions, then :

Defines an empty array of them (there is an element 0)

To add a position to it. (You can change the length dynamically)

(Note, I haven't tested these)

Note that functions return single entities, you can't do the x,y = something (hence there are two functions to get the pointer position).

One final thing to bear in mind ; AGK2 is cross platform. GetPointer and its associated functions are the generic input. It will work fine with a mouse, but it will also work on tablets and phones. One consequence of this is that you cannot track the movements of the mouse unless the pointer is down - cross platform - because on a tablet you don't know where the finger/stylus is unless it's touching the screen
AGK Developer
Years of Service
User Offline
Joined: 1st Jan 2014
Posted: 12th Feb 2015 09:56
I think there are insert commands which will allow you to add data to an array and the array will automatically increase in size accordingly.

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Feb 2015 17:04 Edited at: 12th Feb 2015 17:04
Quote: "I think there are insert commands which will allow you to add data to an array and the array will automatically increase in size accordingly."

That's right...


Just be careful, it will cause the array to be reallocated every few inserts, which may cause a small visible stutter in your game. For small arrays, or use out of the main game loop, it should be fine.

Quidquid latine dictum sit, altum sonatur

Login to post a reply

Server time is: 2023-03-22 05:45:10
Your offset time is: 2023-03-22 05:45:10