Hi there,

one thing I never really understood on programming is how to go with arrays.

Say I have some objects which move (some small static windows, some buttons, etc) how would I go and put the upper left coordinates (x and y) and a third factor (maybe speed) of each into an array and how could I access these values.

So, if my array would look like this:

how do I read out the first couple for the first object, then switch two the next couple, etc?

I already looked at some posts and on one of them bogdan (hi bogdan!) gives a long and detailed answer but I am still not sure about it (sorry bogdan!). I have a code example now, but could someone explain that to me some more? As I already stated some time ago I am very rusty in programming at all due to navy time even though I own a laptop with MASM32 V7 ;D It took me 4 hours to find a simple error in a perl script (a ; was missing :( )

Hope to get some answers

YaWNS aka Stefan K.
Posted on 2001-12-25 10:10:51 by YaWNS
Create a structure:

x dd ?
y dd ?
dx dd ?
dy dd ?
MyObject ENDS
Make some space for objects:
Objects MyObject 256 dup (<>)
Do stuff with objects:
   mov ebx,ADDR Objects + (SIZEOF Objects)

@@:sub ebx,SIZEOF MyObject
mov eax,[ebx].MyObject.x
mov edx,[ebx].MyObject.y
add eax,[ebx].MyObject.dx
add edx,[ebx].MyObject.dy
mov [ebx].MyObject.x,eax
mov [ebx].MyObject.y,edx
invoke DrawObject, eax, edx
cmp ebx,ADDR Objects
jge @B
Posted on 2001-12-25 12:14:08 by bitRAKE
Hi, thanks for your answer, but what did you do with the code?

I just saved the whole site and this is what I saw after looking at the source.

BTW, this does not completely work for me.

I'll try the new version of your code. :alright:

Posted on 2001-12-25 13:25:04 by YaWNS
Hi again, tried the other version and this works great for me. I think I know now how I can handle this stuff.

BTW, why do you start getting the entries of the array from the last one? Is this a must or is this just cause you wanted to. I could also start with the first one and increase allways for the size of the structure, right?

Oh, and why do you include the 0 Entry of the array which results in some big numbers ( I assume these are the adresses ??? ).

Nevertheless, I wish you all some nice christmas days.

YaWNS aka Stefan K.
Posted on 2001-12-25 13:44:01 by YaWNS
I was thinking about BogdanOntanu's post and changed my mind about the implementation - there is no need to have an index counter unless you use it for something else and even then it could be generated. Idealy, I would like to remove all hard coded constants from my code, and make them based on the data or structure definitions (ie using SIZEOF, LENGTHOF). This way less changes will need to be made when the code evolves or is used on another project.

Starting at the end is optional and might not be a good idea - cache works better going forward I think? :) The array should be indexed from zero to one less than the total count. The change is trivial:
	ASSUME ebx: PTR MyObject

mov ebx,OFFSET Objects
@@: mov eax,[ebx].x
mov edx,[ebx].y
add eax,[ebx]._x
add edx,[ebx]._y
mov [ebx].x,eax
mov [ebx].y,edx
add ebx,TYPE Objects
invoke DrawObject, eax, edx
cmp ebx,OFFSET Objects + (SIZEOF Objects)
jne @B
Edit: Sorry, about the code above - this is fixed and should work well? :grin: Thinking about this a little more...it would be nice to not have to reference MyObject in the code at all (ie using something like: ASSUME ebx:PTR (TYPE Objects)). Couldn't find a way to do it.
Posted on 2001-12-25 15:13:45 by bitRAKE