Gave Beebe’s interesting proxy tutorial a try. But when I try to use a non-innate number, it turns out I can only use relative numbers?
[code]
– (Note: Using only the code supplied on the tutorial page)
local wallet = display.newImage(“wallet.png”, 0, 0)
wallet.money = 0
wallet = proxy.get_proxy_for( wallet ) – now it’s a proxy object
function wallet:propertyUpdate(event)
if event.key == “money” then
print(event.value)
end
end
– Attach
wallet:addEventListener( “propertyUpdate” )
– Test function
local function changeMoney()
wallet.money = 500
end
– After 1 second, wallet should become 500
local test = timer.performWithDelay(1000, changeMoney)[/code]
In a standard lua coding environment, if I say wallet.money = 500
, it’s absolute. It’s now 500. But in the above example, well, two things happen:
-
Nothing happens. wallet.money is unchanged. Which is counter to Beebe’s example code where x/y position change, and then propertyUpdate() reports back. The only way to change the property is to use
self[event.key] = self[event.key] + event.value
in the propertyUpdate() code. -
The 500 is reported as a key value (a relative number), so there’s no way to make both absolute and relative changes. If I want to zero out the wallet later, for example, wallet.money = 0 doesn’t do anything, because it’s simply adding zero. I would have to say wallet.money = -wallet.money, which is seems to basically kill any of the original user-friendliness of the approach.
Long story short:
Is there a way to pull-off Beebe’s tutorial, where I can (theoretically) set values as normal and report back, or am I doomed to using relative values? [import]uid: 41884 topic_id: 26638 reply_id: 326638[/import]