Page 2 of 2

Re: question about coordinate unit.

Posted: 29 Mar 2013, 15:21
by zwzsg
Learn to debug then. I advise generously sprinkling your code with Spring.Echo, to find which blocks are run and what are the values of your variables, until you find precisely on which line it is going wrong.

Have Spring windowed and use /luaui reload to shorten the change code - test in Spring cycle.

Re: question about coordinate unit.

Posted: 29 Mar 2013, 15:26
by Broker
zwzsg wrote:Learn to debug then. I advise generously sprinkling your code with Spring.Echo, to find which blocks are run and what are the values of your variables, until you find precisely on which line it is going wrong.

Have Spring windowed and use /luaui reload to shorten the change code - test in Spring cycle.
error is only that I can not get the coordinates

Re: question about coordinate unit.

Posted: 29 Mar 2013, 15:32
by zwzsg
Youth nowadays has it too easy with GetScreenGeometry!
In ye ole days, to retrieve screen size I had to store the arguments a DrawScreenEffects was called with!

Code: Select all

local ScreenWidthInPixels
local ScreenHeightInPixels

function widget:DrawScreenEffects(vsx, vsy)
	ScreenWidthInPixels, ScreenHeightInPixels = vsx, vsy
end
If you want the center of the screen, you have to divide them by two!

Code: Select all

function widget:MouseRelease(x, y, button)

	if not (ScreenWidthInPixels and ScreenHeightInPixels) then
		return
	end

	local result, coords = Spring.TraceScreenRay(ScreenWidthInPixels / 2 ,ScreenHeightInPixels / 2 ,true,false)

end

Re: question about coordinate unit.

Posted: 29 Mar 2013, 15:41
by Broker
zwzsg wrote:Youth nowadays has it too easy with GetScreenGeometry!
In ye ole days, to retrieve screen size I had to store the arguments a DrawScreenEffects was called with!

Code: Select all

local ScreenWidthInPixels
local ScreenHeightInPixels

function widget:DrawScreenEffects(vsx, vsy)
	ScreenWidthInPixels, ScreenHeightInPixels = vsx, vsy
end
If you want the center of the screen, you have to divide them by two!

Code: Select all

function widget:MouseRelease(x, y, button)

	if not (ScreenWidthInPixels and ScreenHeightInPixels) then
		return
	end

	local result, coords = Spring.TraceScreenRay(ScreenWidthInPixels / 2 ,ScreenHeightInPixels / 2 ,true,false)

end
then:
local mapX, mapY, mapZ = unpack(coords)

and I get a point on the map indicates where the center of the screen.
I understand correctly? I can use them in the order of units.

Re: question about coordinate unit.

Posted: 29 Mar 2013, 20:02
by a1983
Man, to write something in lua, you should learn Lua Scripting.
If you want world coordinate then you should use Screen & Window Geometry
As I understood to get world coordinates where pointed center of view doing in such way:

Code: Select all

	local w, h, x, y = Spring.GetViewGeometry()
	Spring.Echo( w, h, x, y )
	
	local info, xyz = Spring.TraceScreenRay( w * 0.5, h * 0.5 , true, false )
	if xyz then
		Spring.Echo( info, unpack( xyz ) )
	else
		Spring.Echo( "sky" )
	end
Using GetScreenGeometry - not valid in windowed mode. You can also try GetWindowGeometry, to see differences.
But if you want to give order to unit, you should learn how to give order and what kind of coordinates used in orders.

Re: question about coordinate unit.

Posted: 01 Apr 2013, 09:53
by Broker
a1983 wrote:Man, to write something in lua, you should learn Lua Scripting.
If you want world coordinate then you should use Screen & Window Geometry
As I understood to get world coordinates where pointed center of view doing in such way:

Code: Select all

	local w, h, x, y = Spring.GetViewGeometry()
	Spring.Echo( w, h, x, y )
	
	local info, xyz = Spring.TraceScreenRay( w * 0.5, h * 0.5 , true, false )
	if xyz then
		Spring.Echo( info, unpack( xyz ) )
	else
		Spring.Echo( "sky" )
	end
Using GetScreenGeometry - not valid in windowed mode. You can also try GetWindowGeometry, to see differences.
But if you want to give order to unit, you should learn how to give order and what kind of coordinates used in orders.
I understand that. however, Lua Scripting does not seem to MSDN. there is nothing except the names of functions. not how to use them, their arguments, return values. so I ask for help. write a few lines of code.

Re: question about coordinate unit.

Posted: 01 Apr 2013, 10:07
by gajop
There is documentation... It may not be perfect but only a few things are unclear imo (and not the stuff you are currently dealing with).

If there's a particular function you are unclear about, ask away. But you should try things out yourself first ;)

Re: question about coordinate unit.

Posted: 01 Apr 2013, 11:17
by Broker
gajop wrote:There is documentation... It may not be perfect but only a few things are unclear imo (and not the stuff you are currently dealing with).

If there's a particular function you are unclear about, ask away. But you should try things out yourself first ;)
Unfortunately my experiments failed. Thank you.

Re: question about coordinate unit.

Posted: 04 Jun 2013, 14:44
by Broker
Broker wrote:
zwzsg wrote:
you are referring to variables outside their scope
This means that you have to change

Code: Select all

function fct()
	if tst then
		local a,b = ...
	end
	Spring.Echo(a,b)
end
into :

Code: Select all

function fct()
	local a,b
	if tst then
		a,b = ...
	end
	Spring.Echo(a,b)
end

I understand. I changed it but nothing happened.
and me again. maybe this time will help me.)))

Re: question about coordinate unit.

Posted: 04 Jun 2013, 14:52
by Jools
gajop wrote: if result == "ground" then
Why should he only process "ground" events? The result can also be "unit" or "feature", in which case you get the coordinated by using Spring.GetUnitPosition() and Spring.GetFeaturePosition()

Re: question about coordinate unit.

Posted: 04 Jun 2013, 17:57
by gajop
Jools wrote:
gajop wrote: if result == "ground" then
Why should he only process "ground" events? The result can also be "unit" or "feature", in which case you get the coordinated by using Spring.GetUnitPosition() and Spring.GetFeaturePosition()
Because it will never return "unit" or "feature" if third param is true, and is used to check if its within map radius or something like that.