Page 1 of 1
[0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 5:37 pm
by StanFear
ok so the problem might not exactly come from the player.real2screenposition() function.
the thing is, when getting the mouse position using this function in the on_put_item event, the calculated position is not always the mouse position, quick way to see that :
make a mod with the on_put_item event, with in it a code that moves the cursor to the position calculated using the function
small sample of code :
Code: Select all
function on_put_item(event)
local player = game.players[event.player_index]
player.cursor_position = player.real2screenposition(event.position)
end
using this code, the cursor will move towards the top left corner of the screen
after some tests, it seems to be linked to the zoom level as the cursor gets moved only when not at zoom level 1.000
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 6:56 pm
by Rseding91
The methods screen2realposition and real2screenposition are left overs of making the trailer and won't work for replays or multiplayer (also don't work for non default zoom as you found).
Most likely they shouldn't exist at all and we just forgot to remove them in the release build

Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 9:53 pm
by StanFear
well, that's a shame ... My mod idea won't ever work then ...
(making a selection mod, to select an area since the deconstruction planner only marks some types of entities and not others (or lack of enteties actually ...))
I actually don't understand why it wouldn't work in multiplayer, isn't the game supposed to simulate other players ? and having their screen resolution and zoom level seems easy enough ... since these functions are linked to the player ...
anyways, I bet the ability to set the player's cursor position is also a leftover ?
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 9:56 pm
by Zeblote
Rseding91 wrote:they shouldn't exist at all and we just forgot to remove them in the release build

I think you meant "we should fix them"
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 10:05 pm
by kovarex
Zeblote wrote:Rseding91 wrote:they shouldn't exist at all and we just forgot to remove them in the release build

I think you meant "we should fix them"
No, we should just remove them, there is no easy way of making it work properly.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 10:11 pm
by Oxyd
StanFear wrote:I actually don't understand why it wouldn't work in multiplayer, isn't the game supposed to simulate other players ? and having their screen resolution and zoom level seems easy enough
Zooming isn't synchronised across multiplayer because it's not necessary. Instead, when you, for example, hover over an entity to select it, we send an event that you selected that entity – that doesn't require sending the exact mouse coordinates. Knowing every player's zoom level isn't necessary to correctly update the game state.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 10:26 pm
by Zeblote
kovarex wrote:Zeblote wrote:Rseding91 wrote:they shouldn't exist at all and we just forgot to remove them in the release build

I think you meant "we should fix them"
No, we should just remove them, there is no easy way of making it work properly.
Can you add events for on_mouse_enter_item (or similar), on_mouse_leave_item, on_mouse_down, on_mouse_dragged and on_mouse_up with world coordinates?
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 10:41 pm
by Oxyd
Zeblote wrote:kovarex wrote:Zeblote wrote:Rseding91 wrote:they shouldn't exist at all and we just forgot to remove them in the release build

I think you meant "we should fix them"
No, we should just remove them, there is no easy way of making it work properly.
Can you add events for on_mouse_enter_item (or similar), on_mouse_leave_item, on_mouse_down, on_mouse_dragged and on_mouse_up with world coordinates?
on_mouse_down, on_mouse_dragged and on_mouse_up again would be problematic as we don't send every mouse movement across the network either, in any coordinate system.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 10:45 pm
by Supercheese
I think on_entity_clicked would be enough, really, since there is even
a mod whose entire purpose is to provide a workaround to the non-existence of this event.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Thu Feb 04, 2016 11:13 pm
by Zeblote
Oxyd wrote:Zeblote wrote:kovarex wrote:Zeblote wrote:Rseding91 wrote:they shouldn't exist at all and we just forgot to remove them in the release build

I think you meant "we should fix them"
No, we should just remove them, there is no easy way of making it work properly.
Can you add events for on_mouse_enter_item (or similar), on_mouse_leave_item, on_mouse_down, on_mouse_dragged and on_mouse_up with world coordinates?
on_mouse_down, on_mouse_dragged and on_mouse_up again would be problematic as we don't send every mouse movement across the network either, in any coordinate system.
Okay, how about the first 2? It'd allow creating custom behaviors for mouse over-ing entities, like showing the range of turrets and so on.
Even if the on_mouse_down only works while hovering over an entity it'll still be useful.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Fri Feb 05, 2016 7:30 am
by StanFear
Oxyd wrote:StanFear wrote:I actually don't understand why it wouldn't work in multiplayer, isn't the game supposed to simulate other players ? and having their screen resolution and zoom level seems easy enough
Zooming isn't synchronised across multiplayer because it's not necessary. Instead, when you, for example, hover over an entity to select it, we send an event that you selected that entity – that doesn't require sending the exact mouse coordinates. Knowing every player's zoom level isn't necessary to correctly update the game state.
ok, there is no way then to make a mod that allows selecting areas then ? the only thing I needed was to be able to move the player's cursor to a very close position, like one pixel away and back (this is where I used the functions) to be able to trigger the on_put_item again if the player is still holding the mouse button
Maybe being able to set the cursor position using world position would be enough
(you havn't answerd by the way, is the writablility of the player's cursor a leftover too ?)
if you want to understand how I was using it, you can check there :
https://github.com/stanfear/FactorioMod ... ontrol.lua
(notice the attempt at nullifying the random effects of the functions ...)
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Fri Feb 05, 2016 11:14 am
by kovarex
Most of the information said here is wrong.
The information about the hover/unhover is already there, it is the select/deselect input action, so you can use the selected to get this data.
The on entity clicked also already exists as an lua event for a long time.
On the other hand, method to get position of a mouse isn't and won't be supported, as it would required to basically send the input action with the mouse coordinate every tick.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Fri Feb 05, 2016 11:19 am
by Zeblote
kovarex wrote:The information about the hover/unhover is already there, it is the select/deselect input action, so you can use the selected to get this data.
I can't find this anywhere on your api pages. What's it called exactly?
kovarex wrote:
On the other hand, method to get position of a mouse isn't and won't be supported, as it would required to basically send the input action with the mouse coordinate every tick.
Not if we could have client-sided scripts...
Usually you'd need stuff like dragging to mark an area or similar, which can all be done on the client. Only when whatever dragging was supposed to do is finished, it becomes relevant for other clients.
Most of the features you create probably work similar, only sending info when it's needed to reproduce an action. Why can't we implement systems of similar complexity as mods?
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Fri Feb 05, 2016 1:51 pm
by kovarex
Zeblote wrote:kovarex wrote:The information about the hover/unhover is already there, it is the select/deselect input action, so you can use the selected to get this data.
I can't find this anywhere on your api pages. What's it called exactly?
kovarex wrote:
On the other hand, method to get position of a mouse isn't and won't be supported, as it would required to basically send the input action with the mouse coordinate every tick.
Not if we could have client-sided scripts...
Usually you'd need stuff like dragging to mark an area or similar, which can all be done on the client. Only when whatever dragging was supposed to do is finished, it becomes relevant for other clients.
Most of the features you create probably work similar, only sending info when it's needed to reproduce an action. Why can't we implement systems of similar complexity as mods?
Custom area selection request from the script (or tied to an item) could be definitly done, so mods can do stuff like this.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Fri Feb 05, 2016 2:52 pm
by kovarex
Zeblote wrote:kovarex wrote:The information about the hover/unhover is already there, it is the select/deselect input action, so you can use the selected to get this data.
I can't find this anywhere on your api pages. What's it called exactly?
https://forums.factorio.com/wiki/inde ... r#selected
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Fri Feb 05, 2016 8:15 pm
by StanFear
kovarex wrote:Custom area selection request from the script (or tied to an item) could be definitly done, so mods can do stuff like this.
well, that would be awesome (this is what I was trying to do from the start) espacially for my subsurface mod where I want to be able to select an area and can't use the on_marked_for_deconstruction event since there is no items to select
that would be a good enough fix for me !
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Tue Feb 23, 2016 11:05 pm
by StanFear
I know the has been "resolved", but has the cursor position been changed to be ingame position and not screen position ? (would seem useless if not, since there is no way to convert game position to screen position anymore)
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Wed Feb 24, 2016 1:29 am
by Rseding91
StanFear wrote:I know the has been "resolved", but has the cursor position been changed to be ingame position and not screen position ? (would seem useless if not, since there is no way to convert game position to screen position anymore)
cursor_position is write only (since that won't change anything that would mess with replays/multiplayer) so while you can write it - there's not much use to do so.
Re: [0.12.22] player.real2screenposition() not working properly
Posted: Wed Feb 24, 2016 8:28 am
by StanFear
Rseding91 wrote:cursor_position is write only (since that won't change anything that would mess with replays/multiplayer) so while you can write it - there's not much use to do so.
ok, but this does not answer my question, what kind of position de we need to give it ? ingame or screen ?
having it set to ingame position would still allow me to do a selection mod (I think

),
having it set to screen position would be quite a bad idea imo, since there is no way to translate positions anymore, plus, what happens if I set the cursor position to -30,-30 ? or at 1900, 1000 if the player only have a 720p screen ?