Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
DaComputerNerd

How to get dimension of player with debug card

Question

I was reading through the Debug component's functions, and I am not really sure how to do what I am attempting to do. Essentially, I am trying to get the dimension ID of each player returned by component.debug.getPlayers(). I don't really understand how to call the "Player object" functions, or the "World object" functions. The example on the component's page (https://ocdoc.cil.li/component:debug) does not demonstrate how to do this. I tried component.debug.getWorld(players) and component.debug.getPlayers().getWorld() to get the world the player is in (i is a previously defined variable), neither worked. I can't figure out the correct way to use these functions.

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0
  • Solution

Such objects are just tables, they must be processed in the correct sequence.

players = component.debug.getPlayers() -- get a players list

for i = 1, players.n do
  print(players[i]) -- display the name of the next player
end

player = component.debug.getPlayer(players[1]) -- get player proxy by name from list
world = player.getWorld() -- get the proxy of the world in which the player is located
print(world.getDimensionName()) -- print the name of the world


-- Or you can get everything at once
players = component.debug.getPlayers()
for i = 1, players.n do
  print(players[i], component.debug.getPlayer(players[i]).getWorld().getDimensionName())
end

 

Link to post
Share on other sites
  • 0

@Log you beat me to it by about a minute :p. So I'll just add how to get a useful list OP mentioned.

local component = require "component"
local debug = component.debug
local players = {}

for _, name in ipairs(debug.getPlayers()) do
  local world = debug.getPlayer(name).getWorld()
  
  table.insert(players, {
      name = name,
      dimension = {
          name = world.getDimensionName(),
          id = world.getDimensionId()
        }
    })
end

print(players[1].name, players[1].dimension.name, players[1].dimension.id) --> "Molinko"	"overworld"		"0"

 

Link to post
Share on other sites
  • 0

Ok now I'm having a different issue with this. When I try to run this code, it has an error pointing to the line with the for loop in tellRawToPlayers saying "attempt to index number value"

never mind, i made a stupid mistake

however, calling the following

component.debug.getPlayer(players[i]).getWorld().getDimensionID()

it says "attempt to call field getDimensionID (a nil value)"

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.