Posted: 27th Jun 2007 14:54
Hi,

I am trying to read a series of numbers from a .txt file and convert those numbers into a RGB value using a function.

Basically, the .txt file is looking like so:
255,0,0
0,0,64
41,201,32

My function reads each line in the file and converts the numbers on each line into 3 series of numbers (separated by the comma).
Inside the function it reads (on the first line): R = 255 G = 0 B = 0.
So I store this in a RETURNDATA() array: RETURNDATA(1) = R RETURNDATA(2) = G etc.

The function did its purpose and I want to convert the RETURNDATA() numbers into a RGB Value: color = RGB( RETURNDATA(1), etc. )
But RETURNDATA(x) is now 0. (!) How come it can be 255 inside the function and 0 outside the function? I don't get it.

my code, for better explanation, is attached.
Posted: 27th Jun 2007 15:03
One of your functions doesn't return a value. Could that be the problem?
Posted: 27th Jun 2007 15:09
Did you mean the AddButton function? That doesn't need to return anything to the user.

I forgot to metion the relevant functions are tgui_LoadGui( file$ ) and tgui_SystemGetColorFromFile().
Posted: 27th Jun 2007 16:25
is some var going out of scope when the function ends?
Posted: 27th Jun 2007 16:35
Make sure that the DIM for the array in question is outside of the function, at the start of the main program.

If the DIM is inside the function then the values you place into it don't exist outside of that function - they are 'local'.

[Edit] Just had a quick look at your code. As you are opening files to read and write in one function and actually doing the reading/writing in another function, you may possibly have to set everything up as global variables.

Maybe doing what you are doing is probably better achieved with procedures rather than functions.

TDK_Man
Posted: 27th Jun 2007 17:11
I think the problem may be with reading the gui file in correctly. I haven't counted the number of lines, but if you delete all the gui file except for the line 255,0,0, and in the function delete all the lines which call the tgui_SystemGetColorFromFile() function except for the line TGUI_COLOR.buttonNormalBorder = tgui_SystemGetColorFromFile(), it works fine. This suggests to me it is probably reading the wrong line somewhere.


<edit> - yes, that's it. In your load_gui function, you read 15 strings from the gui file before attempting to read the string 255,0,0. But you gui file has 24 strings before the 255,0,0 string. Moving the 255,0,0 string onto the 16th line does the trick. You must always make sure that the routine for reading in strings from a file matches the contents of the file.
Posted: 27th Jun 2007 18:11
Well spotted Ric!

TDK_Man
Posted: 27th Jun 2007 19:14
ah, how careless of me
Thank you Ric.
Posted: 28th Jun 2007 0:27
Did you mean the AddButton function? That doesn't need to return anything to the user.


Yes I did. I can see now that I was wrong. I carelessly assumed that the variable "returnVal" was supposed to be the return value of that function. I realise now that it was used as the return value of a different function. Silly me.

Well spotted Ric (again).

(@Ric I know you are honeymooning later in the year - but aren't you sailing a bit close to the wind by spending time here so soon after the wedding?? )