Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Error out if empty username.
Browse files Browse the repository at this point in the history
The player_locations sensor is the only place where the empty username
actually matters (the empty string is otherwise perfectly permissible as
a table key -- it's when we try to use it as a GUI element name that it
fails).

I could technically have provided a simple prefix or suffix to help, but
I'd rather just fail outright in this one rare case.

Fixes #15 and bumps the version to 0.4.1.
  • Loading branch information
narc0tiq committed Aug 31, 2015
1 parent 26fd340 commit 5a3cc62
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.4.1
1 change: 1 addition & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sensor.play_time.format=Play time: __1__.
sensor.player_locations.name=Player locations
sensor.player_locations.format=Players:
sensor.player_locations.err_no_name=You have no multiplayer username, player list disabled.
sensor.player_locations.surface_fragment=on __1__
sensor.player_locations.settings.title=Player location settings
sensor.player_locations.settings.show_player_index=Show player index
Expand Down
16 changes: 13 additions & 3 deletions value_sensors/player_locations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,20 @@ end
function sensor:update_ui(owner)
local player = game.get_player(owner.player_index)
local sensor_settings = global.evogui[player.name].sensor_settings[self.name]
local gui_list = owner[self.name].player_list

for _, p in ipairs(game.players) do
if owner[self.name].player_list[p.name] == nil then
owner[self.name].player_list.add{type="label", name=p.name}
if not p.name or p.name == '' then
if gui_list.error == nil then
gui_list.add{type="label", name="error", caption={"sensor.player_locations.err_no_name"}}
end
break
end

if gui_list.error ~= nil then gui_list.error.destroy() end

if gui_list[p.name] == nil then
gui_list.add{type="label", name=p.name}
end

local direction = '?'
Expand Down Expand Up @@ -154,7 +164,7 @@ function sensor:update_ui(owner)
table.insert(desc, ' ' .. direction)
end

owner[self.name].player_list[p.name].caption = desc
gui_list[p.name].caption = desc
end
end

Expand Down

0 comments on commit 5a3cc62

Please sign in to comment.