can't create a variable with that name

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

can't create a variable with that name

Post by jmburnod » Wed May 27, 2009 12:51 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed May 27, 2009 2:15 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

can't create a variable with that name

Post by jmburnod » Wed May 27, 2009 5:32 pm

Hi Mark,

Thank for your disponibility

The explicitVariables = false

Regards

Jean-Marc

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed May 27, 2009 6:47 pm

Hi Jean-Marc,

Has your problem been solved now?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

can't create a variable with that name

Post by jmburnod » Wed May 27, 2009 7:21 pm

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
Last edited by jmburnod on Wed May 27, 2009 8:42 pm, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed May 27, 2009 8:40 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed May 27, 2009 8:46 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

can't create a variable with that name

Post by jmburnod » Wed May 27, 2009 9:26 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed May 27, 2009 11:13 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

can't create a variable with that name

Post by jmburnod » Thu May 28, 2009 9:01 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu May 28, 2009 10:33 am

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

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: can't create a variable with that name

Post by Mag » Wed Mar 13, 2013 2:27 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: can't create a variable with that name

Post by Mark » Wed Mar 13, 2013 2:46 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: can't create a variable with that name

Post by Mag » Wed Mar 13, 2013 2:54 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: can't create a variable with that name

Post by Mark » Wed Mar 13, 2013 3:07 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply