10 May 2020, 14:33 | #1 |
Registered User
Join Date: Apr 2018
Location: Germany
Posts: 189
|
How to create a 'Array of structs' in AMOS?
I'm currently playing around with AMOS.
What I not made out yet is how to manage complex types. E.g. a list of Points. Each point has an X and Y value and maybe some other properties, too. How can an Array of points be created with AMOS? |
10 May 2020, 16:56 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
|
You have to do direct manipulation of an Amos bank with Peek, Poke, Deek, Doke, Leek and Loke.
|
11 May 2020, 09:39 | #3 |
Registered User
Join Date: Apr 2018
Location: Germany
Posts: 189
|
Oh I think I aim for something else. Only data - no gfx at this moment.
I try to achieve something that in C would be done like this: Code:
struct MyPoint { ULONG X; ULONG Y; }; MyPoint listOfPoints[10]; |
11 May 2020, 10:02 | #4 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,406
|
I don't think you can make something like structs in AMOS. I used to "emulate" arrays of structs by having a number of separate arrays containing the individual entries of the struct I wanted and using their name to group them.
So your example would become something like Code:
DIM POINT_X(10),POINT_Y(10) |
11 May 2020, 10:31 | #5 |
Registered User
Join Date: Apr 2018
Location: Germany
Posts: 189
|
This will do it, at least for objects with not too many properties:-) Tank you.
|
11 May 2020, 12:07 | #6 | |
Registered User
Join Date: Nov 2004
Location: Germany
Posts: 629
|
How about multi dimensional arrays ?
I'm emulating types with them like: dim Point(10,2) 10 would be the number of points. (reference number) I have to define where to save the coordinates. e.g. 0=x , 1=y So to access the 5th point x and y coordinate, i'm using : PosX=Point(5,0) PosY=Point(5,1) To make it readable i have used extra variables (which may not change in the code) like: T_X=0 T_Y=1 So the above code would be (a bit more readable too, well in case of debugging!): PosX=Point(5,T_X) PosY=Point(5,T_Y) btw. Quote:
With Amos Data bank you can allocate a desired amount of memory, in which you can (L)(D)Poke the desired values. |
|
11 May 2020, 12:13 | #7 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,406
|
Yeah, multidimensional arrays also work just fine
The reason I personally tended to do the many 1D arrays way myself was simply one of clarity and allowing multiple types to be mixed. You can instantly see what POINT_X and POINT_Y are referring to, in a multidimensional array you'd have to remember. Now obviously for something as simple as coordinates this is quite doable, but as structures become more complicated it's easier to start making errors when using multidimensional arrays. But use whatever works for you |
11 May 2020, 12:18 | #8 |
Wipe-Out Enthusiast
Join Date: Nov 2005
Location: .
Age: 43
Posts: 2,538
|
depends on the use though - multi-dimensional arrays are quite a big performance hit in AMOS if accessed inside your game loop. I prefer the PEEK/POKE method personally
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
68040 const array init | phx | Coders. Asm / Hardware | 6 | 14 February 2020 09:27 |
Creating an array gives me a Guru | Shatterhand | Coders. Blitz Basic | 14 | 13 August 2019 20:54 |
Array putting garbage in register | Locash | Coders. Asm / Hardware | 8 | 04 March 2018 13:03 |
Limited Array Of CDTV Games | fondpondforever | Retrogaming General Discussion | 9 | 23 July 2015 14:20 |
Blitz2: Pointer to array | idrougge | Coders. Blitz Basic | 3 | 26 March 2015 21:44 |
|
|