RE: Making UDT's using Sequence?

new topic     » topic index » view thread      » older message » newer message

Here's how you might define your 'game' structure.

-- first make constants to define sequence entries (for readability)
constant
   x    = 1,
   race = 2,
   trn  = 3,
   rst  = 4,
   name = 5,
   last = 6

-- define 'game' as sequence
sequence get_game, game

-- now you might want your file 'gamestat.dat' to just be a sequence
--   that you can read with get()
--   i.e. your files contains: {0,{0,0,0,0,0,0,0,0,0,0,0},"","","",0}
--   or whatever you want your initial values to be.

-- initialize 'game' from file
integer fn

fn = open( "gamestat.dat", "r" )
get_game = get(fn)
if get_game[1] = GET_SUCCESS then
   game = get_game[2]
end if   
close(fn)

-- now you can access the elements of game like this:
--  some_integer = game[x]
--  some_sequence = game[race]
--  another_integer = game[race][1]
--  another_sequence = game[trn]
--  etc...

-- you can also change your structure like this:
--  game[x] = some_integer
--  game[race][1] = another_integer
--  etc..

-- when the game is over, save your data with print (so you can read 
-- using get() for the next game):
fn = open( "gamestat.dat", "w" )
print( fn, game )
close(fn)

Using sequences this way is a 'feature' of Euphoria and really has 
little to do with Win32Lib.  (I'm not sure what could be added to the 
library to make this any easier.)

Hope this helps...
-- Brian


timelord at zebra.net wrote:
> I have tried to convert this small bit of code I wrote last year using
> RapidQ into
> Euphoria, but I'm still having problems understanding the Sequence idea.
> 
> *  I don't understand how to make a Sequence like a User Defined Type. 
> *  Can't get the Data files to load either...
> *  My programming experience is limited to QuickBasic and RapidQ. 
> 
> Listed below is part of the Euphoria code I have been trying to get to 
> work.  
> I also included parts of the RQ code to show what I'm trying to do...
> It's much easier to make Windows using Euphoria over RQ but working with 
> UDT's
> is alot easier... (hint, hint to the win32lib staff :)

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu