Page 1 of 1

Get player surface during on_nth_tick

Posted: Sat Nov 06, 2021 3:09 pm
by FuryoftheStars
To be specific, I'm trying to update the functionality of the mod Steinios Wind Sensor (a EvoGUI plugin mod) for use in another mod I'm making. However, in the wind sensor mod, they pull the wind data only from game.surfaces["nauvis"]. I'd like to change this so it'll pull from whichever surface the player is currently on, but player is unavailable in on_nth_tick, which I guess kind of makes sense. I'm not fluent enough in Factorio control stage modding to know how to solve this.

Re: Get player surface during on_nth_tick

Posted: Sat Nov 06, 2021 3:19 pm
by Xorimuth
FuryoftheStars wrote:
Sat Nov 06, 2021 3:09 pm
To be specific, I'm trying to update the functionality of the mod Steinios Wind Sensor (a EvoGUI plugin mod) for use in another mod I'm making. However, in the wind sensor mod, they pull the wind data only from game.surfaces["nauvis"]. I'd like to change this so it'll pull from whichever surface the player is currently on, but player is unavailable in on_nth_tick, which I guess kind of makes sense. I'm not fluent enough in Factorio control stage modding to know how to solve this.
All player objects are available in on_nth_tick using game.get_player(). Which player do you want though? Since that mod's description says single-player only, you can use game.get_player(1) to get access to the player. Each player has a surface attribute which you can use to get the surface.

PS this is data stage modding not control stage modding :)

Re: Get player surface during on_nth_tick

Posted: Sat Nov 06, 2021 3:27 pm
by FuryoftheStars
Xorimuth wrote:
Sat Nov 06, 2021 3:19 pm
FuryoftheStars wrote:
Sat Nov 06, 2021 3:09 pm
To be specific, I'm trying to update the functionality of the mod Steinios Wind Sensor (a EvoGUI plugin mod) for use in another mod I'm making. However, in the wind sensor mod, they pull the wind data only from game.surfaces["nauvis"]. I'd like to change this so it'll pull from whichever surface the player is currently on, but player is unavailable in on_nth_tick, which I guess kind of makes sense. I'm not fluent enough in Factorio control stage modding to know how to solve this.
All player objects are available in on_nth_tick using game.get_player(). Which player do you want though? Since that mod's description says single-player only, you can use game.get_player(1) to get access to the player. Each player has a surface attribute which you can use to get the surface.

PS this is data stage modding not control stage modding :)
The old wind sensor mod is single player, but is EvoGUI? I don't see that in it's description and what parts of the code I've been able to parse do make references to player objects like it should support multi. That game.get_player() may work, though, thanks!

Oh, this is going to be confusing if control.lua is called data stage and there are data.lua files that are a different stage....

Re: Get player surface during on_nth_tick

Posted: Sat Nov 06, 2021 4:04 pm
by Xorimuth
FuryoftheStars wrote:
Sat Nov 06, 2021 3:27 pm

Oh, this is going to be confusing if control.lua is called data stage and there are data.lua files that are a different stage....
Oh no I am actually an idiot... control.lua is of course control stage modding.

Re: Get player surface during on_nth_tick

Posted: Sat Nov 06, 2021 6:30 pm
by mrvn
Shouldn't this be a sensor you place on a surface and then it shows the direction on that surface?

If it's something the player carries around then you have to keep a list of all players and update each players sensor.

Re: Get player surface during on_nth_tick

Posted: Sat Nov 06, 2021 8:57 pm
by FuryoftheStars
Well, I don’t think the EvoGUI mod works that way. I don’t think I can tie it’s readout to the presence of an entity. And I didn’t want to have to create my own UI….

That said, as I’ve been mulling this situation around more, I think while the EvoGUI mod may itself work ok with multiplayer and multisurface, I’m not so sure that using its remote.call function to add and update what that mod refers to as sensors will. As a part of the remote.call functions, it does not take in player information. This means I’m either adding one sensor that gets its data overwritten from each player, or I put a separate sensor for each player that is visible to all players, cluttering the UI.