question about coordinate unit. - Page 2

question about coordinate unit.

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7001
Joined: 16 Nov 2004, 13:08

Re: question about coordinate unit.

Post by zwzsg » 29 Mar 2013, 15:21

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.
0 x

Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post by Broker » 29 Mar 2013, 15:26

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
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7001
Joined: 16 Nov 2004, 13:08

Re: question about coordinate unit.

Post by zwzsg » 29 Mar 2013, 15:32

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
0 x

Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post by Broker » 29 Mar 2013, 15:41

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.
0 x

a1983
Posts: 55
Joined: 02 Dec 2009, 12:01

Re: question about coordinate unit.

Post by a1983 » 29 Mar 2013, 20:02

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.
0 x

Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post by Broker » 01 Apr 2013, 09:53

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.
0 x

gajop
Moderator
Posts: 2923
Joined: 05 Aug 2009, 20:42

Re: question about coordinate unit.

Post by gajop » 01 Apr 2013, 10:07

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 ;)
0 x

Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post by Broker » 01 Apr 2013, 11:17

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.
0 x

Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post by Broker » 04 Jun 2013, 14:44

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.)))
0 x

User avatar
Jools
XTA Developer
Posts: 2767
Joined: 23 Feb 2009, 16:29

Re: question about coordinate unit.

Post by Jools » 04 Jun 2013, 14:52

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()
0 x

gajop
Moderator
Posts: 2923
Joined: 05 Aug 2009, 20:42

Re: question about coordinate unit.

Post by gajop » 04 Jun 2013, 17:57

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.
0 x

Post Reply

Return to “Lua Scripts”