Local buttonPos = go.get_position("#ButtonSTART") -- No ERROR, but x & y are always 0?

Hi,

Stuck on this:
local buttonPos = go.get_position("#ButtonSTART") – No ERROR, but x & y are always 0 ?

function on_input(self, action_id, action)
	-- Add input-handling code here
	-- Remove this function if not needed

	local mX = action.screen_x
	local mY = action.screen_y	
	mX = mX * ( (360/WindowWidthTrue) )
	mY = mY * ( (640/WindowHeightTrue) )
--	label.set_text( "#MouseXY", "X:" .. tostring(mX) .. "/Y:" .. tostring(mY) )
	
	if action_id == hash("ClickGUI") then
		if CurrentScreen == 2 then
			local buttonPos = go.get_position("#ButtonSTART") -- No ERROR, but x & y are always 0 ?

label.set_text( "#MouseXY", "BX:" .. tostring(buttonPos.x) .. "/BY:" .. tostring(buttonPos.y) )
--buttonPos.x = 180
--buttonPos.y = 430

			local buttonWidth = (251/2)
			local buttonHeight = (38/2)
			if (  ( mX > (buttonPos.x - buttonWidth) and mX < (buttonPos.x + buttonWidth) ) and ( mY > (buttonPos.y - buttonHeight) and mY < (buttonPos.y + buttonHeight) )  ) then
				go.set("#ButtonSTART", "scale.x", 0.85)
				go.set("#ButtonSTART", "scale.y", 0.85)
				go.set("#ButtonSTARTText", "scale.x", 0.85)
				go.set("#ButtonSTARTText", "scale.y", 0.85)
			end
		end
	end
end

I am a slow learner, but very persistent…

J.

URL to ZIP of entire project:
http://fallenangelsoftware.com/stuff/files/RedLightRacer/RedLightRacer.zip

When it 100% done, it will be open-source

J.

go.get_position(“#ButtonSTART”) returns the position of the game object in which #ButtonSTART sits in (in this case), which is just (0,0,0), as that is where the game object Screen-2-Title sits. There is no way to get the position of a component in a game object.

You are trying to do GUI through game objects, which is nightmare fuel, as you can see below. There is a much, much, much better way to do it. Many people have already linked it before: the tutorial called Colorslide. Please check it out. Please.

3 Likes

Hi,

Thanks for the reply.
I’ll take a 2nd look at “Color Slide” tutorial…

J.

2 Likes

Hi Again,

Our GUI buttons MUST animate, is that possible?
(button animation is simple scale down and scale back up)

Let us know before we jump into this (ie: “Color Slide” tutorial)

Thanks!

J.

Maybe you should read the GUI overview before you continue? It outlines all the possibilities with GUIs.

2 Likes