Page 1 of 2

can't create a variable with that name

Posted: Wed May 27, 2009 12:51 pm
by jmburnod
can't create a variable with that name

Hi All,

I created a local variable for one script and i use it

If i use after an other script with local variable no declared

I have sometimes one error message :

"compilation error at line 4 (Chunk: can't create a variable with that name (explicitVariables?)) near "old", char 18"

I think it is linked

If i use declared local variable one time the others scripts must also declare every varaible ?


Regards

Jean-Marc

Posted: Wed May 27, 2009 2:15 pm
by Mark
Ji Jean-Marc,

Why do you have explicitVariables set to true?

If you define a variable inside a handler, then you have to declrare it inside all other handlers that use the same variable as well. You can also declare it outside the handler. If you declare it outside a handler, it is sufficient to declare once in all other scripts that contain handlers using your variable. For example:

Code: Select all

-- script of button 1
local lSomeVar
on mouseUp
  put x into lSomeVar
  foo
end mouseUp

on foo
  put someFunction(lSomeVar) into fld 1
end foo
This is one script, with two handlers, which both use the same variable lSomeVar. Ths variable needs to be declared only once, outside all handlers.

If you want to use the same variable with a similar name in a different script, you have to declare it again and it will still be a different variable.

Code: Select all

-- card script
local lSomeVar
function someFunction theVar
  put theVar into lSomeVar
  return "Whatever Valiue"
end someFunction
The two variables lSomeVar in the button script and the card script are two different variables, which are declared for all handlers in those scripts. They don't affect each other and here I'm using a (otherwise useless) function to transfer the value of one variable lSomeVar to another variable lSomeVar.

If you use global variables, you need to declare them in all scripts again, if declared outside all handlers, just like the local variables. However, the variable will be the same in both scripts and a value stored in one script will still be available in any other script.

If this doesn't solve your problem, you might want to post your script.

Best,

Mark

can't create a variable with that name

Posted: Wed May 27, 2009 5:32 pm
by jmburnod
Hi Mark,

Thank for your disponibility

The explicitVariables = false

Regards

Jean-Marc

Posted: Wed May 27, 2009 6:47 pm
by Mark
Hi Jean-Marc,

Has your problem been solved now?

Best,

Mark

can't create a variable with that name

Posted: Wed May 27, 2009 7:21 pm
by jmburnod
Hi Mark,

I has not my problem been solved

The editor return the same error sometimes.

It work fine, but if i change something in some script of the card, the compilation return :

sometimes :
"compilation error at line 2 (Chunk: can't create a variable with that name (explicitVariables?)) near "bufNomCurIM"

and sometimes:
(Handler: can't find handler) near "DeImage"



for a simple line "put the short name of the target into bufNomCurIM"

Code: Select all

-- The script of 15 images of the card
on mouseup
DeImage
end mouseup	

-- The DeImage handler is in the card script

on DeImage
set the rect of grc "Entoure" to the rect of the target
    put the short name of the target into bufNomCurIM
   put char 9 to 10 of bufNomCurIM into LeNumIm
  put the MonSon of the target into MonFile
   put "UnCadre"&LeNumIm into LeCadre
JoueSon MonFile,LeCadre
end DeImage

on JoueSon f,c
   put f into MonFile
   put c into LeCadre
   set the bottomleft of player "Parleur" to the topleft of grc LeCadre
   set the currenttime of player "Parleur" to 0
   set the filename of player "Parleur" to MonFile
   start player "Parleur"
end JoueSon
Thank one more

Jean-Marc

Posted: Wed May 27, 2009 8:40 pm
by bn
actually I think it is a bug in Rev. I once in a while have this in 3.5. Not expicit variables on/off on my part. It just goes away, after restart.
Bernd

Posted: Wed May 27, 2009 8:46 pm
by Mark
Bernd,

It seems you're right. Jean-Marc, you might put your code in a try end-try control structure and post the resulting error here, even though it might not help.

Code: Select all

on foo
  try
    -- your code here
  catch myErr
    put myErr
  end try
end foo
You might also put true into gRevDevelopment. This might bring up some additional error messages, which might be worth investigating.

Best,

Mark

can't create a variable with that name

Posted: Wed May 27, 2009 9:26 pm
by jmburnod
Hi Mark and Bernd,

gRevDevelopment = true return the same result

The sequence is like that

• I open the revfile
• I clic on the image and the script work fine
• I open the card script
• I delete an empty line (the btn "compile" is enabled)
• I clic on the btn "compile"
• "compilation error at line 2 (Chunk: can't create a variable with that name (explicitVariables?)) near "bufNomCurIM"
• I save (the save process work)
• I close the script editor
• I clic on the image
• I have an error "UneImage4": execution error at line 2 (Handler: can't find handler) near "DeImage"

I can't test by the try control, but rev don't understand "DeImage" the second time

Regards

Jean-Marc

Posted: Wed May 27, 2009 11:13 pm
by bn
Jean-Marc,

I have no clear idea.
But I would try to put the text of the card script (without the empty lines) into the script of the stack. Clear the card script completely.
See if that compiles. Maybe there is an invisible ASCII character that bugs Rev. (just a guess)
Or take the card script and put it into the script of just one image and clear the card script, see if that compiles.
Take the card scrpt and put it into an text editor and turn it to plain text and paste it over all of the card script and see if that works.
You might want to try this on a copy of your original stack.
You could also clear the card script and retype the card script.

These are all guesses, but you could try.
Sometimes if Rev behaves funny it helped when I just deleted the Rev preferences.

regards
Bernd

can't create a variable with that name

Posted: Thu May 28, 2009 9:01 am
by jmburnod
Hi Bernd and Mark,

Good new :D
Bernd have a good solution way

I check the rev preferences and i watch the "compilation strict" is true

I set it to false and the rev editor work

I hope it is the solution

My prev post before the good new :


I don't believe this mistake is not linked with an invisible char in the script
I tested it :

• I do a new stack (one card)

Code: Select all

The script of the card
on tsimple
   put 1 into buf
end tsimple

I have the same results after the compilation :

card id 1002: compilation error at line 2 (Chunk: can't create a variable with that name (explicitVariables?)) near "buf", char 10

I watch : put char 10 of " put 1 into buf" return "i" (the "i" of "into")

Regards

Jean-Marc

Posted: Thu May 28, 2009 10:33 am
by bn
Jean-Marc,
good for you.
Actually that would not be a bug of Rev but the expected behavior.

I understood that you had turned that off. Anyway the point here is to keep on trying, eventually most things can be straightened out or worked around.

regards
Bernd

Re: can't create a variable with that name

Posted: Wed Mar 13, 2013 2:27 pm
by Mag
Same problem here. I checked if some invisible chars are present but not found any. The problem happens with the scripts of the menubar, it seems to me that the project lost it's stability after I used Menu Builder. To solve temporary the problem, I have to quit and re-open LiveCode every time I make changes on the scripts.

LC 5.5.4 and OS X 10.8.2

Re: can't create a variable with that name

Posted: Wed Mar 13, 2013 2:46 pm
by Mark
Hi,

Are you seeing exactly the same error message as OP in 2009? If not, could you post the exact error message here?

Kind regards,

Mark

Re: can't create a variable with that name

Posted: Wed Mar 13, 2013 2:54 pm
by Mag
Hi Mark,

sure:
button "File": compilation error at line 73 (Chunk: can't create a variable with that name (explicitVariables?)) near "myT", char 41
button "Help": compilation error at line 4 (Chunk: can't create a variable with that name (explicitVariables?)) near "theLink", char 57
button "Edit": compilation error at line 42 (Chunk: can't create a variable with that name (explicitVariables?)) near "textToProcess", char 29
They appairs as errors everytime I try to save the script.

Re: can't create a variable with that name

Posted: Wed Mar 13, 2013 3:07 pm
by Mark
Hi,

Could you post the first 10 lines of the script of your Help menu?

What do you get if you execute
put the explicitVariables
in the message box?

Is the Strict Compilation Mode option in the Script Editor pane of the preferences window turned off?

Do you use any plug-ins that don't come with the original LiveCode installation?

Kind regards,

Mark