PDA

View Full Version : ask help for XSI PPG coding


fangye100
08-20-2013, 02:29 AM
hi , guys.
I am a new learner studying XSI coding . currently I am going to do a custom UI for my own script which need PPG knowledge.
My script wrote like this
////////////////////////
var myPset=ActiveSceneRoot.AddProperty("CustomProperty",false,"Mytest");
var myLayout=myPset.PPGLayout;
var b=1;
myLayout.AddRow()
myLayout.AddButton("a","button");
myLayout.Logic=a_OnClicked.toString();
myLayout.EndRow()
myLayout.Language = "JScript" ;
InspectObj(myPset);
function a_OnClicked(){
LogMessage(b);
}
/////////////////////
this is a very simple test coding , I dont know why my button function can not read variable "b" . very times when I run this script ,it always failed and show "b is not defined " .
I dont understand that I already defined var b=1 at the very beginning , how com the function can not visit it ?

anything wrong I did ? hope somebody help me :love:

ThE_JacO
08-20-2013, 11:45 PM
When posting code, please use code tags.
Text enclosed between [code ] text here [/code ] (without the spaces before brackets) will appear properly formatted.

Also, there's a scripting subforum, moving the thread there for you, next time please post in the right section right away :)

As for the actual question, your variable b lives in the scope of the script you're using to create the PPG. Once the PPG is created its own logic DOES NOT have that variable.
You need it in the logic of the command you're implementing, or it needs to be passed as an argument for it to work.

ThE_JacO
08-23-2013, 02:08 AM
Stephen must have read this thread judging by his last blog entry:
http://xsisupport.com/2013/08/22/ppg-callbacks-and-variable-scope/

That's a more extensive and illustrated explanation of what I mentioned, go and read it.

CGTalk Moderation
08-23-2013, 02:08 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.