Read Array data (from file) and use it

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
Raziel
Posts: 5
Joined: Mon May 24, 2010 3:37 pm

Read Array data (from file) and use it

Post 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
Attachments
level load array test.zip
Project file without my messed up tryouts...
(32.36 KiB) Downloaded 506 times
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Raziel
Posts: 5
Joined: Mon May 24, 2010 3:37 pm

Post 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...
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
Array.zgeproj
(518 Bytes) Downloaded 526 times
Raziel
Posts: 5
Joined: Mon May 24, 2010 3:37 pm

Post 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?
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

8)

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

K
Raziel
Posts: 5
Joined: Mon May 24, 2010 3:37 pm

Post 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.
Attachments
level load array test.zip
(1.12 KiB) Downloaded 502 times
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
LoadMap.zip
(774 Bytes) Downloaded 536 times
Raziel
Posts: 5
Joined: Mon May 24, 2010 3:37 pm

Post 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!
Post Reply