PDA

View Full Version : loading external variables, problem with string to num



upuaut8
April 8th, 2002, 02:52 PM
ok.. I really feel like pounding my head against a wall here.

I'm importing variables from a regular txt file. I have dynamic text fields on the main timeline that pick up and show these variables. I know that they are coming into the player at _root, or _level0

rows="5"; is one of them. When I do a debug/List variables, that's what it shows me.

I do a
trace(rows);
and I get
"undefined"

I do a
parseInt(rows);
and I get
"NaN"

What is it exactly that I can't get?

A) Why can't I trace the @#%$ variable?
since you should be able to trace anything, and
B) Why can't I convert it to a number from the string of "5"?

any clue?? I'm on 5 days of insomnia, and I just can't figure out what I'm doing wrong..

sinfiniti
April 8th, 2002, 03:11 PM
let's see your text file. most of the time the problem is there.
also, do you have a flag at the end of the text file to let the timeline know that all the text has loaded?
:)
jeremy

upuaut8
April 8th, 2002, 03:34 PM
&date0=2002-04-06%2009%3A17%3A08&name0=administrator&email0=dhaisley%40centerspin.com&site0=www.centerspin.com&comment0=Well%20no%20matter%20who%20created%20it%2 C%20I%27m%20in%20charge..&date1=2002-04-06%2009%3A16%3A11&name1=Upuaut&email1=administrator%40centerspin.com&site1=www.centerspin.com&comment1=Hey%2C%20get%20the%20hell%20out..%20this% 20is%20MY%20creation&date2=2002-04-06%2009%3A12%3A19&name2=David&email2=Upuaut%40centerspin.com&site2=www.centerspin.com&comment2=Well%2C%20here%27s%20the%20guestbook..%20 or%20at%20least%20a%20Beta%20version.%20Please%20s ign%20it%20and%20let%20me%20know%20what%20you%20th ink.&rows=3&flag=true

sinfiniti
April 8th, 2002, 04:27 PM
ok, i got the file to load the variables. here's what i did.
frame 1:
loadVariables ("loadme.txt", this);
frame 3:
if(flag=="true"){
trace("playing through");
play();
} else {
trace("looping");
gotoAndPlay(_currentframe-1);
}
frame 4:
for(ii in this){
if(typeof(ii)=="string"){
trace (ii+": "+this[ii]);
}
}
stop();

...........................
now, to convert a string that is a number to a number, i do this:
rows*=1;

and i did change the text file for clarity...
date0=2002-04-06%2009%3A17%3A08&
&name0=administrator&
&email0=dhaisley%40centerspin.com&
&site0=www.centerspin.com&
&comment0=Well%20no%20matter%20who%20created%20it%2 C%20I%27m%20in%20charge..&
&date1=2002-04-06%2009%3A16%3A11&
&name1=Upuaut&
&email1=administrator%40centerspin.com&
&site1=www.centerspin.com&
&comment1=Hey%2C%20get%20the%20hell%20out..%20this% 20is%20MY%20creation&
&date2=2002-04-06%2009%3A12%3A19&
&name2=David&
&email2=Upuaut%40centerspin.com&
&site2=www.centerspin.com&
&comment2=Well%2C%20here%27s%20the%20guestbook..%20 or%20at%20least%20a%20Beta%20version.%20Please%20s ign%20it%20and%20let%20me%20know%20what%20you%20th ink.&
&rows=3&
&flag=true

you can put line breaks in your txt file if you put an amphersand at the end of the line.

hope that helps.
:)
jeremy

upuaut8
April 8th, 2002, 04:42 PM
yup.. the only reason I format it like that is it is the way my php returns it.

I'm unclear on something though.

The trace function I really could care less if I get to work.. I hardly ever use it, which is why I don't really have a good understanding of it yet. (I use text fields which display various info and then I just delete that layer when I have everything working.:) )

The important part of this though is the conversion.

why would rows*=1 return a numerical value if it's a string?

upuaut8
April 8th, 2002, 04:46 PM
Well.. it works.. that's all I really care about.. I'd still like to know why it does.

Thanks for the help. Much appreciation

upuaut8
April 8th, 2002, 04:52 PM
OMG!!!!!

ok, never mind.. you want to know what I was doing wrong? It had nothing to do with the variables at all. The problem was in my loop

if (hub.flag=="true"){
&nbsp &nbsp &nbsp &nbsp gotoAndPlay(4);&nbsp &nbsp &nbsp &nbsp
}

was set to

if (hub.flag=true){
&nbsp &nbsp &nbsp &nbsp gotoAndPlay(4);&nbsp &nbsp &nbsp &nbsp
}

:)

I'm an idiot

The reason this screwed up the trace was, I was tracing code that couldn't exicute because the variables hadn't loaded yet.. as a flag=true statement will simply send that playhead onto frame 4 without even pausing.

Or at least that's what I believe was the problem as it is the only thing that I changed and now parseInt(); works like it's supposed to.

Jesus I can be dumb when I'm tired.

I am not Jubba
April 8th, 2002, 05:10 PM
dont feel bad upu, i'm dumb all the time.

ilyaslamasse
April 8th, 2002, 05:14 PM
Don't say that, Jubby. You're just... different, that's all.

pom :lol:

sinfiniti
April 8th, 2002, 07:36 PM
anyways...
trace just displays what you tell it to in the output window.
example:
trace("hello");
if you put that in a movie and tested it the output window would show 'hello'.
i use trace a lot, and often create a function to trace sets of variables when they change.
:)
jeremy

I am not Jubba
April 8th, 2002, 07:56 PM
how would you do that because yesterday i was trying to follow my variables while doing that Text animation and i couldn't do it...

upuaut8
April 9th, 2002, 01:05 AM
I would suspect that you either "loop" your trace function, or place it in a bunch of places throughout your code.

My problem with trace, I think, was two fold.

A) I was not getting all the variables by the time the trace was called, and
B) I was trying to trace the parseInt(); function which could not read the number anyway.

It was something like this

topStack=parseInt(rows)-1;

Does anyone know if that looks wrong? I was thinking that maybe it should be

topStack=(parseInt(rows))-1;

would it make any difference which way I did that?