PDA

View Full Version : if variable=variable simple problem!!!!



lplover2k2
July 2nd, 2004, 03:02 AM
Ok i'm having this problem;i have tried a lot of times to try to find what is wrong but could not;it looks pretty simple though but i'm a newbie;

here is the situation:
I have 2 buttons:
-Next page
-Previous page

a dynamic text box where i load an external text;it is called "contents"(the var).

my "Previous page" button works fine while i'm having problem with my "next page" button.

I use loadVariablesNum("../texts/"+pagenum+".txt", 0);
So that when i press on
next page" button;the pagenum is incremented and it loads 1.txt , 2.txt ,etc...(where in each text; "contents" variable is loaded).

I also use a variable(lastpage) so that to stop the "next page" button to go further than the last page.

I load the lastpage variable value from an external text too.

here is the code the "next page" button:

on (release) {
if (pagenum=lastpage) {
break;
} else {
pagenum = pagenum+1;
loadVariablesNum("../texts/"+pagenum+".txt", 0);
}
}


The "next page" button doesn't stop when pagenum=lastpage.

Any idea why? thanks in advance

GreenLantern
July 2nd, 2004, 03:41 AM
Your problem lies in this line:
if (pagenum=lastpage) {

"=" is used to set something equal to something else.
"==" is used to compare if two things are equal.

Change the line to this:
if (pagenum==lastpage) {

lplover2k2
July 2nd, 2004, 05:25 AM
i have tried "==" too but it is the same result :(

GreenLantern
July 2nd, 2004, 05:44 AM
ok next question, where and how are you setting the variable lastpage?

lplover2k2
July 2nd, 2004, 06:59 AM
i load the variable "lastpage" from an external text file.

GreenLantern
July 2nd, 2004, 08:17 AM
It has to be something in the scope or depth of your lastpage variable.

Put a trace(lastpage); right before the if statement to make sure it is being set correctly.

lplover2k2
July 2nd, 2004, 08:44 AM
still no good :( it keeps on loading the pages although it has reached the last page :(

claudio
July 2nd, 2004, 08:56 AM
The problem is that you are misusing the break command. It can only be used to stop loopings such as for, for in, while or do while.
You could use something like this:

on (release) {
if (pagenum<=lastpage) {
pagenum = pagenum+1;
loadVariablesNum("../texts/"+pagenum+".txt", 0);
}
}

lplover2k2
July 2nd, 2004, 09:03 AM
no good either;i have a question is it possible to put variable==variable in if command???

claudio
July 2nd, 2004, 09:04 AM
Yes, whenever comparing two values or variables, you have to use the == operator.

lplover2k2
July 2nd, 2004, 09:09 AM
but i doesn't seem to work :(

claudio
July 2nd, 2004, 09:12 AM
Then you must be doing something wrong.
Can you upload your files?

lplover2k2
July 2nd, 2004, 11:46 AM
Then you must be doing something wrong.
Can you upload your files?here they are with the texts

http://www.geocities.com/lplover2k2/project.zip

copy and paste in address bar if it does not work

lplover2k2
July 15th, 2004, 10:42 AM
here they are with the texts

http://www.geocities.com/lplover2k2/project.zip

copy and paste in address bar if it does not work
anyone can help??? please

Prophet
July 16th, 2004, 04:35 AM
else if(condition){action}
as opposed to else{condition;action}
and i wrote a mini tut on IF statements here: http://www.kirupaforum.com/forums/showthread.php?t=60750&highlight=if+statements
why not do a search?

Prophet.

lplover2k2
July 17th, 2004, 01:54 PM
thanks i have reada you tutorial but still don't know why my code doesn't work :(