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: 7049
Joined: 16 Nov 2004, 13:08

Re: question about coordinate unit.

Post 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.
Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post 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
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: question about coordinate unit.

Post 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
Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post 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.
a1983
Posts: 55
Joined: 02 Dec 2009, 12:01

Re: question about coordinate unit.

Post 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.
Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post 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.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: question about coordinate unit.

Post 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 ;)
Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post 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.
Broker
Posts: 156
Joined: 02 Jul 2012, 13:16

Re: question about coordinate unit.

Post 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.)))
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: question about coordinate unit.

Post 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()
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: question about coordinate unit.

Post 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.
Post Reply

Return to “Lua Scripts”