New developer here… This should be easy for someone with experience
I’m creating a new field in an interface tag and trying to set the value before I run the object. I print the field inside the object and it is always empty. It is as if the field is READONLY from outside the object. Here is some test code from the final ScreenGraph tutorial
Near the top of TutorialPanelSetScene.xml I have inserted this line of code:
sub init()
print “Init ()”
m.top.backgroundURI = “pkg:/images/rsgde_bg_hd.jpg”
m.readContentTask = createObject(“roSGNode”, “ContentReader”)
m.readContentTask.observeField(“content”, “setcategories”)
m.readContentTask.contenturi = “http://www.sdktestinglab.com/Tutorial/content/categoriescontent.xml” m.readContentTask.test = “TEST”
m.readContentTask.control = “RUN”
end sub
In ContentReader.xml I have added this code:
****
and this code:
sub getcontent()
print “in ContentReader getcontent()”
print "m.top.contenturi is " m.top.contenturi print "m.top.test is " m.top.test
…
What firmware# is that? Sometimes due to race conditions assignments between threads may fail, though i doubt this is your case.
Follow the adage “divide and conquer”, e.g. put a print right after assignment and so on, till you narrow where the issue happens
m.readContentTask.test = "TEST"
? "checking on m.readContentTask.test", m.readContentTask.test
Actually I did try printing the value right after assignment and the value is there, but in the task the value is still missing. I must be doing something really dumb.
Thanks for your assistance.
and what if you dump the whole node, not individual fields?
just do “? m.top” in getContent(). scrutinize the list of fields.
also try different name than “test” (sanity check)
Wait a minute. Scratch everything older than this post. I did what you said and got the same results, but when i scrolled up I noticed there were two sets of printouts from the Task. The first set had the fields filled in. Evidently the example creates another instance somewhere else and calls the task where I have not set the “test” value. That’s what I get for trying to recreate an issue in the example code. I thought everyone would be more familiar with the example code.
So I returned the code that I am writing, put in similar print statements, and found that my Task object is getting fired when I do the CreateObject before I fill in the fields. So the question is what would make the Task fire before I set the Control field to “RUN”?
Here is the code in the calling procedure:
Sub Init()
Print "*************************************"
Print “CountrysideMainScene.Init ()”
If you have any ideas they would be greatly appreciated. In the mean time I am going to cut down my code to do nothing but call an empty task and build it up from there.
Issue Resolved.
I misinterpreted the purpose of the Init function in the task. It is supposed to run when the object is created. The FunctionName that it sets is what gets triggered when the Control field is set to RUN. I made the mistake of trying to call the main part of the task in the Init function.
Quite.
“Init” is the object initializer (post-constructor).
Running a task causes a new run-thread to be spawned, stealing “m” for it and leaving a depleted copy behind.
how would you read the xml file if it was located in your components folder? My private channel does not require internet access so the xml files need to be local.
Thanks
“piyushg098” wrote:
was this issue resolved? I am also facing this issue.
which of the two issues mentioned above are you referring? Maybe start a new topic and link to this one. The first guy figured out his problem, the second guy jacked the thread with a totally off topic post.