View Full Version : Very simple syntax error using `source $v;`
Hey fellow Mellers!
I have a serious yet simple question! Why do I get a syntax error if I use a variable with the source command?
$freakShow = "D:/PROJECTS/2008/prefs/userHotKeys.mel"; //directory path
source "D:/PROJECTS/2008/prefs/userHotKeys.mel"; //how come THIS works <
source $freakShow; //yet this doesn't? <
Your help would be appreciated! I need to run some files that aren't sourceable directly- yet are in an internalVar directory.
Thanks,
|
|
scroll-lock
03-31-2009, 11:51 AM
hm, a colleague of mine asked me the same last week. We couldn't find an answer.... but in our case we just used the direct source ..... I don't know why, but it's really strange why the other one is not working..
cbamber85
03-31-2009, 03:48 PM
You probably need the escape character in front of the foward slashes, whereas the source command will have built-in formatting functions.
_stev_
03-31-2009, 03:51 PM
Yeah, it's weird. I always source scripts from a proc anyway though so that you can catch errors.
global proc int sourceScript(string $script) {
if ( exists($script) ) {
if ( catch( eval( "source \"" + $script + "\"" ) ) ) {
return false;
} else {
return true;
}
} else {
return false;
}
}
$freakShow = "D:/PROJECTS/2008/prefs/userHotKeys.mel";
sourceScript $freakShow;
That works, thanks!
So I guess the key was to use the \" special character, to add a " on either side.
Thank you very much!
ewerybody
04-01-2009, 09:11 AM
confirmed! but ..Weird!
eval ("source \"" + $filePath + "\"");
works...
@stev! nice script. You could actually shorten it a little though:
global proc int sourceScript(string $script) {
if (( exists($script) ) && (! catch( eval( "source \"" + $script + "\"" ) ) ))
return true;
return false;
}
// or
global proc int sourceScript(string $script) {
if ( exists($script) )
if (! catch( eval( "source \"" + $script + "\"" ) ) )
return true;
return false;
}
CGTalk Moderation
04-01-2009, 09:11 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.