question about coordinate unit.
Moderator: Moderators
Re: question about coordinate unit.
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.
Have Spring windowed and use /luaui reload to shorten the change code - test in Spring cycle.
Re: question about coordinate unit.
error is only that I can not get the coordinateszwzsg 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.
Re: question about coordinate unit.
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!
If you want the center of the screen, you have to divide them by two!
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
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.
then: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!
If you want the center of the screen, you have to divide them by two!Code: Select all
local ScreenWidthInPixels local ScreenHeightInPixels function widget:DrawScreenEffects(vsx, vsy) ScreenWidthInPixels, ScreenHeightInPixels = vsx, vsy end
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
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.
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:
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.
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
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.
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.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:Using GetScreenGeometry - not valid in windowed mode. You can also try GetWindowGeometry, to see differences.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
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.
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
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.
Unfortunately my experiments failed. Thank you.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
Re: question about coordinate unit.
and me again. maybe this time will help me.)))Broker wrote:zwzsg wrote:This means that you have to changeyou are referring to variables outside their scopeinto :Code: Select all
function fct() if tst then local a,b = ... end Spring.Echo(a,b) end
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.
Re: question about coordinate unit.
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 wrote: if result == "ground" then
Re: question about coordinate unit.
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.Jools wrote: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 wrote: if result == "ground" then