Simple problem, I hope!

Hi,

I have a simple problem, I hope!

I am reading a variable from a text file

tr_1 = East&

into a dynamic text field tr_1.

When I try and trace the value of the text field I cannot get the value I have just read in.

i.e.

loadVariablesNum("./correctTrains.txt", 1);

var count = 0;

trace (“dyn text =” + this.tr_1 );

‘correctTrains.txt’ looks like this

tr_1=East&

The thing is I can see the word East in the text field, however the trace outputs this

dyn text =

Can anyone help??

L.

Shouldn’t that read &tr_1=East?

Also if you’re using MX - why don’t you use loadVars()

*Originally posted by flex *
**Also if you’re using MX - why don’t you use loadVars() **

Neither makes a diference, and I really need to be able trace the value that I am reading in, as until I am sure it is being assign to my var, I cannot do a string compare.

Any help would be appreciated.

If you’re loading into level 1 - loadVariablesNum("./correctTrains.txt", 1); , try

trace (“dyn text =” + _level1.tr_1 );

*Originally posted by flex *
**If you’re loading into level 1 - loadVariablesNum(“./correctTrains.txt”, 1); , try

trace (“dyn text =” + _level1.tr_1 ); **

I tried it, no joy :frowning:

Try this - the fla has nothing but a dynamic text box with the var set as _level1.test.

In the first frame I use

loadVariablesNum(“test.txt”, 1);

to load a variable called test from a text file called test.txt.

Make sure the fla and the text file are in the same folder and test the movie - you should see that it displays the loaded variable.

Check your swf and text file are in the same folder.
Check that you are using _level1.variable name for the variable.
And check that all the variables are actually loaded before you call them.

Correction - your swf and text file don’t need to be in the same folder - I meant make sure the path to the text file is correct.

I got it working!

I used an off screen empty movie called dirHolder that contained the following code

onClipEvent(data){
_root.dirLoad();
}

Then in the main actions of the movie (on layer 1) I did the following

stop();
//loadVariablesNum("./correctTrains.txt", 1);

loadVariables("./correctTrains.txt", _root.dirHolder);

function dirLoad(){
//initialize i
var i=0;
var count=0;
dir_trans1 = dirHolder["_level1.tr_1"];
trace(_level0.train1_results + “=” + dir_trans1);
if (_level0.train1_results == dirHolder["_level1.tr_1"]) {
count++;
}
dir_trans2 = dirHolder["_level1.tr_2"];
trace(_level0.train2_results + “=” + dir_trans2);
if (_level0.train2_results == dirHolder["_level1.tr_2"]) {
count++;
}
dir_trans3 = dirHolder["_level1.tr_3"];
trace(_level0.train3_results + “=” + dir_trans3);
if (_level0.train3_results == dirHolder["_level1.tr_3"]) {
count++;
}
dir_trans4 = dirHolder["_level1.tr_4"];
trace(_level0.train4_results + “=” + dir_trans4);
if (_level0.train4_results == dirHolder["_level1.tr_4"]) {
count++;
}
dir_trans5 = dirHolder["_level1.tr_5"];
trace(_level0.train5_results + “=” + dir_trans5);
if (_level0.train5_results == dirHolder["_level1.tr_5"]) {
count++;
}
dir_trans6 = dirHolder["_level1.tr_6"];
trace(_level0.train6_results + “=” + dir_trans6);
if (_level0.train6_results == dirHolder["_level1.tr_6"]) {
count++;
}
dir_trans7 = dirHolder["_level1.tr_7"];
trace(_level0.train7_results + “=” + dir_trans7);
if (_level0.train7_results == dirHolder["_level1.tr_7"]) {
count++;
}
dir_trans8 = dirHolder["_level1.tr_8"];
trace(_level0.train8_results + “=” + dir_trans8);
if (_level0.train8_results == dirHolder["_level1.tr_8"]) {
count++;
}
dir_trans9 = dirHolder["_level1.tr_9"];
trace(_level0.train9_results + “=” + dir_trans9);
if (_level0.train9_results == dirHolder["_level1.tr_9"]) {
count++;
}
dir_trans10 = dirHolder["_level1.tr_10"];
trace(_level0.train10_results + “=” + dir_trans10);
if (_level0.train10_results == dirHolder["_level1.tr_10"]) {
count++;
}

_level1.score = count;

if (count == 10) {
	_level1.statement = "Excellent";
}
else if (count > 5) {
	_level1.statement = "Not Bad";
}
else {
	_level1.statement = "Very Poor Attempt";
}	

}

Got the string comparison going between the Radio Buttons passed (cheers for that Flex) and the value I am loading into the dyn text fields from the data file.

All works with about an hour to spare :).

Thanks for your help gain Flex.

I was going to sugges loading the variables with

mcname.loadVariables();

but I thought there was a reason that you wanted to use loadVarsNum, as the disadvantage of loading to a level is you have to refer to the level. Loading into an mc is the preferred method.

Glad you got it working.

Just wanted to add that I think the problem was you were calling the variables before they were loaded. With loadVariablesNum you have to manually use code to check if the variables are loaded before you can use them, but with MX you can use the
onClipEvent (data) which checks to see if the data has been loaded before it’s safe to use it.

EDIT: And the game fla - I did it in request of cybergold, but I get people asking me to help, and then no response so I think I’m going to concentrate on my own projects more - but it wouldn’t be fair to put the fla up because although the coding is mine - the graphics are his. But I am working on another game - for which I put a post in the design forum for a designer - and maybe I’ll put the fla of that on my site. There are already some game fla’s you can download.

*Originally posted by flex *
**I was going to sugges loading the variables with

mcname.loadVariables();

but I thought there was a reason that you wanted to use loadVarsNum, as the disadvantage of loading to a level is you have to refer to the level. Loading into an mc is the preferred method.

Glad you got it working. **

Thanks for your help :slight_smile: