[0.12.22] player.real2screenposition() not working properly

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

[0.12.22] player.real2screenposition() not working properly

Post 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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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 :)
If you want to get ahold of me I'm almost always on Discord.

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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 ?
Last edited by StanFear on Thu Feb 04, 2016 9:57 pm, edited 1 time in total.

Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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"

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

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

Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

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

Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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?

Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

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

Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

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

Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

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

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

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

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

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

Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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? :o

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?

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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? :o

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.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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? :o
https://forums.factorio.com/wiki/inde ... r#selected

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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 !

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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)

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
StanFear
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sun Dec 15, 2013 2:49 pm
Contact:

Re: [0.12.22] player.real2screenposition() not working properly

Post 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 ?

Post Reply

Return to “Resolved Problems and Bugs”