Page 1 of 1

Read Array data (from file) and use it

Posted: Mon May 24, 2010 4:14 pm
by Raziel
Hi,

I'm new here and at first i would like to thank Shvillr for his help during my very first steps.

I want to do a few things and it seems like I need your help.
Right now I managed to load a value from a file into a variable and display this value in different colors depending on the value.
I use the TextFloatRef field in the RenderText item like MyVariable.value and it displays e.g. 65 if an A is in the textfile.

My next step was going to read a value out of a persistent array.
(two dimensions)
But I dont know how to address it. MyArray[1,1] does not work.
Choosing TextArray in the Text item does not show anything.

How to read out this data? Do I have to initialize something first?

My next step will be reading in data into an array from a file.
Two dimensional array (49x49). I have to loop the read in process for each line but where and which item?

And what does the FileNameFloatRef field in the File item does?

Thanks in advance
Raziel

Posted: Mon May 24, 2010 4:35 pm
by Kjell
Hi Raziel,

The property you assign FileMoveData to has to be a Float ( you're using a Integer ). This is a old* limitation that should be pretty easy to lift .. but for the time being, just stick to Float :wink:

And FileNameFloatRef is another old* feature that lets you add a number to a filename when you want to save / load many files ( for example .. level0, level1, level2 etc ). These days you can simply change the FileName using a ZExpression instead.

*From back when ZGE only supported Variable Type = Float and nothing else.

Welcome to the club ~
Kjell

Posted: Mon May 24, 2010 4:58 pm
by Raziel
Ok, float is my first choice now :)

Still i can't draw a value out of the array.
In the RanderText Item i can enter MyVariable.value in the TextFloatRef field and it displays something but how to draw e.g. MyArray[1,1] ?
Or any other value out of the array...

Posted: Mon May 24, 2010 5:17 pm
by Kjell
:)

The TextFloatRef property is only for Floats. Simply set the Text property directly using a ZExpression when you want to display the content of a Array cell. Attached is a basic example.

K

Posted: Mon May 24, 2010 5:32 pm
by Raziel
Ok, got it :D

If you could make such a simple example for the loading process it would be great.
Just a textfile loaded into a two dimensional array.
It is a For loop right?

Posted: Mon May 24, 2010 5:38 pm
by Kjell
8)

Check out FileDemo.zgeproj in your ZGameEditor/Projects/FileDemo folder :wink:

K

Posted: Mon May 24, 2010 9:35 pm
by Raziel
I produce a crash :oops:

I make a loop with as many iterations as SizeDim1 or SizeDim2
During my iterations I want to use FileMoveData item but I don't know how?
Here the not messed up file. (removed my attemps)
Reading into variable works. Reading out and drawing out of array too now (thanks) but reading from file into array makes problems.

Posted: Mon May 24, 2010 9:52 pm
by Kjell
Hi Raziel,

Try the attached example .. it won't get any easier then that. Keep in mind that I've removed all line breaks ( Carriage Return + Line Feed ) from Map.txt for simplicity's sake.

K

Posted: Mon May 24, 2010 10:02 pm
by Raziel
Hey, thank you again Kjell!

Code: Select all

Array[MapX.Iteration,MapY.Iteration] = Data;
That is what I needed. I have to dump it itno a temporary variable before storing into an array. Slowly I start understanding...

Will try more and continue.

Thank you very much!