function init(self)
self.my_created_object = factory.create(“#factory”, nil, nil, {my_value = 1})
– communicate with the object
msg.post(msg.url(nil, self.my_created_object), “hello”)
end
And then let the new game object have a script attached:
go.property("my_value", 0)
function init(self)
-- do something with self.my_value which is now one
end
But how can i get the original value, 1? Deleting the go.property line is not working.
If you have a property called my_value, its value will be set by the factory. If you want the original value (in this case 0) you would just omit the {my_value=1} when creating the instance.
Well, declare them using go.property() in your projectile script and then pass them in when you call factory.create(). In the init() function of your projectile script pick up the self.x and self.y use them to set position using go.set_position().
Oookay. I was totally misunderstanding the go.property use. It’s a declaration and not a modification of the variable !
My tower is now properly sending fireballs. Thanks a lot for your help
Correct. Anything you declare using go.property(“foobar”, 123) will be:
accessible as self.foobar from the script where it is declared
accessible from other scripts using go.get("url_or_id_to_game_object", "foobar") (note that this is a bit slow and shouldn’t be used excessively)
accessible from the Properties window in the editor when you select the script when it’s attached to a game object (this is a perfect way to expose scriptable properties to non developers or simply as a quick way to reuse a script and modify it’s behaviour from the editor instead of doing it via code)
animatable (is that a word?) using go.animate("#", "foobar", go.PLAYBACK_ONCE_FORWARD, 567, go.EASING_LINEAR)
a valid property to set when calling factory.create("#factory", nil, nil, { foobar = 567 })