News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help with structs...

Started by Foulone, March 02, 2005, 05:38:26 AM

Previous topic - Next topic

Foulone

I want to create a structure for use with a high score table, something of the nature:

struct highscores
hs_score dd 0
hs_name db 4
ends
(producing a constant highscores_struct_len = 8, if possible)

then populate my highscore table using the struct, something like

highscore_table:
highscores 5,abc
highscores 10,def
highscores 15,ghi

producing the following data
highscore_table
dd 5
db "abc",0
dd 10
dd "def",0
dd 15
dd "ghi",0

is this possible? what would be the correct syntax


donkey

MAX_HIGH_SCORES equ 10

highscores STRUCT
hs_score DD ?
hs_name DB 4 DUP (?)
highscores ENDS

.DATA
Scores highscores MAX_HIGH_SCORES DUP (<?>)
index dd ?
szname db "abc",0

.CODE
mov eax, [index]
mov [Scores[eax].hs_score], 15
invoke lstrcpyn, [Scores[eax].hs_name], offset szname, 4


[index] would contain a number from 0 to MAX_HIGH_SCORES-1 that would be the position in the array where the high score is placed.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

manhattan

For constant initialization you can also use


highscores struct
hs_score dd ?
hs_name db 3 dup (?)
_zero db 0
highscores ends

highscore_table highscores <5, "abc">
                highscores <10, "def">
                highscores <15, "ghi">

Foulone