How to set label position programatically?

Why doesn’t the indicated line work? The line is being triggered by a keypress.

I’ve tried using ‘Position’, ‘position’ and supplying a vector3 or even ‘position.x’ and supplying just a number but none works. I’ve tried addressing it as ‘/go#label’ or just ‘#label’.

According to the API reference go_set() accepts the ‘url of the game object or component having the property’ and help says ’ Apart from the properties Id , Position , Rotation and Scale the following component specific properties exist:"

What am I doing wrong?

function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
	print("Touched")
	label.set_text("#label", "Touched")
elseif action_id == hash("moveup") and action.pressed then	
	go.set("/go#label", "position", vmath.vector3(0, 0 ,0)) -- <--doesn't work
end

end

You need to give the label a GO as its parent and then change the GO’s position. You do not change the positions of components at runtime.

Build prototypes with collections (and spawn with collection factories) instead of GOs when you need complex hierarchies like these, then you can address the GOs within the collection relatively too.

1 Like

gui.set_position does not work at runtime?

This function is used in .gui_script files and only works on GUI nodes (box, text, pie etc).

This question is about the Label component.

1 Like

yes. thx

I see, thanks!