Hello guys, need your help. I need to get g.o. position and then set it to another object but i dont know how to do that. In fact i want to attach gui element to g.o.
I know about set and get functions, also i used paths. I missing something fo sure,
Would be great if someone can show me working code for my sitution, Thank you.
function update(self, dt)
gui.set_position("pie",go.get_position("hero/ship/ship"))
end
for example for this code i gettin this:
ERROR:SCRIPT: main/gui/gui.gui_script:22: bad argument #3 to 'get_position' (GOScriptInstance expected, got userdata)
stack traceback:
[C]: in function 'get_position'
main/gui/gui.gui_script:22: in function <main/gui/gui.gui_script:21>
same error anyway mb i just cant use this function (go.get_position) in gui script? i try’d it in common script and it works. but in gui script i see this.
“main/gui/gui.gui_script:24: in function <main/gui/gui.gui_script:23>
ERROR:SCRIPT: main/gui/gui.gui_script:24: bad argument #3 to ‘get_position’ (GOScriptInstance expected, got userdata)
stack traceback:
[C]: in function 'get_position’
main/gui/gui.gui_script:24: in function <main/gui/gui.gui_script:23>
”
You cannot mix gui and go functions. In a .gui_script file you can only use gui.* functions and in a .script function you can only use go.* functions. You need to use message passing if you wish to pass a game object position to a gui script.
i’m Sorry for bothering you, but can you help me with that. What exaclty i have to do with vector3 message?
Right now i have go.script with this code:
function update(self, dt)
local p = go.get_position()
msg.post("main:/gui/gui#gui", "pos_update", {pos = p})
And gui.gui_script:
function on_message(self, message_id, message, sender)
if message_id == hash("pos_update") then
gui.set_position("pie",message.pos)
end
end
Error:
ERROR:SCRIPT: main/gui/gui.gui_script:35: bad argument #1 to 'set_position' (userdata expected, got string)
stack traceback:
[C]: in function 'set_position'
main/gui/gui.gui_script:35: in function <main/gui/gui.gui_script:33>
ERROR:GAMESYS: Error when dispatching message to gui scene: -2. Message 'pos_update' sent from main:/ship#script to main:/gui/gui#gui.
Hmm, it seems like there’s something wrong with the data passed in the message. Everything looks ok though. Could you please pprint(message) in gui.gui_script and post back here with the result?