English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. AMOS

 
 
Thread Tools
Old 10 May 2020, 14:33   #1
thyslo
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?
thyslo is offline  
Old 10 May 2020, 16:56   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
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.
Samurai_Crow is offline  
Old 11 May 2020, 09:39   #3
thyslo
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];
So that in my program a list of 10 virtual points can be hold.
thyslo is offline  
Old 11 May 2020, 10:02   #4
roondar
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)
This is not perfect by any stretch of the imagination, but it IMHO does help.
roondar is offline  
Old 11 May 2020, 10:31   #5
thyslo
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.
thyslo is offline  
Old 11 May 2020, 12:07   #6
Dan
Registered User
 
Dan's Avatar
 
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:
Oh I think I aim for something else. Only data - no gfx at this moment.
Peek and pokes (look the post#2), in amos, are used for Amos Banks.
With Amos Data bank you can allocate a desired amount of memory, in which you can (L)(D)Poke the
desired values.
Dan is offline  
Old 11 May 2020, 12:13   #7
roondar
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
roondar is offline  
Old 11 May 2020, 12:18   #8
Hungry Horace
Wipe-Out Enthusiast
 
Hungry Horace's Avatar
 
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
Hungry Horace is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:57.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.18530 seconds with 13 queries