RobloxLsp icon indicating copy to clipboard operation
RobloxLsp copied to clipboard

"Workspace" & "Game" are treated as an undefined global

Open phoriah opened this issue 1 year ago • 7 comments

Meanwhile it's another way to reference the "workspace" & "game".

print(Workspace==workspace, Game==game) --> true, true

phoriah avatar Mar 22 '23 13:03 phoriah

Workspace isn't a global it's a service so this error is correct, workspace is just a shortcut for accessing it without having to game:GetService("Workspace"):

do -- service access
    local Workspace = game:GetService("Workspace")
    print(Workspace) -- no error
end

do -- shortcut global access
    print(workspace)
end

-- these two examples are the same, the first is just longer

shirovian avatar Mar 30 '23 04:03 shirovian

Workspace isn't a global it's a service so this error is correct, workspace is just a shortcut for accessing it without having to game:GetService("Workspace"):

print(workspace)
print(game.Workspace)
print(Workspace) -- This should be treated the same as workspace in terms of highlighting, IMO.
print(game:GetService("Workspace"))

phoriah avatar Mar 30 '23 12:03 phoriah

Workspace isn't a global it's a service so this error is correct, workspace is just a shortcut for accessing it without having to game:GetService("Workspace"):

print(workspace)
print(game.Workspace)
print(Workspace) -- This should be treated the same as workspace in terms of highlighting, IMO.
print(game:GetService("Workspace"))

I think Workspace should be treated as it is now, because it is just a service, the documentation I linked earlier affirms this. All workspace does is give you a shortcut to it, which admittedly to me, on Roblox's part, is pretty confusing.

Workspace isn't a global and it isn't workspace so highlighting it as such would be deceptive wouldn't you agree? In my opinion the syntax highlighting should highlight strictly what something really is, as it does now.

image

They are just pre-defined globals, whereas Workspace isn't a global, you have to define it or access it through other globals, making it a non-global.

For clarity on how I see this, this is all the same as saying RunService or Debris are treated as undefined globals.

Meanwhile it's another way to reference the "workspace".

Keep in mind that this is the other way around, workspace is another way to reference Workspace.

shirovian avatar Mar 30 '23 13:03 shirovian

Workspace isn't a global it's a service so this error is correct, workspace is just a shortcut for accessing it without having to game:GetService("Workspace"):

print(workspace)
print(game.Workspace)
print(Workspace) -- This should be treated the same as workspace in terms of highlighting, IMO.
print(game:GetService("Workspace"))

I think Workspace should be treated as it is now, because it is just a service, the documentation I linked earlier affirms this. All workspace does is give you a shortcut to it, which admittedly to me, on Roblox's part, is pretty confusing.

Workspace isn't a global and it isn't workspace so highlighting it as such would be deceptive wouldn't you agree? In my opinion the syntax highlighting should highlight strictly what something really is, as it does now.

image

They are just pre-defined globals, whereas Workspace isn't a global, you have to define it or access it through other globals, making it a non-global.

For clarity on how I see this, this is all the same as saying RunService or Debris are treated as undefined globals.

Meanwhile it's another way to reference the "workspace".

Keep in mind that this is the other way around, workspace is another way to reference Workspace.

Did you run my code example? Then, can you explain why the third line references Workspace instance just like the other lines? And no, you don't need to pre-define it 😌

phoriah avatar Mar 30 '23 14:03 phoriah

For clarity on how I see this, this is all the same as saying RunService or Debris are treated as undefined globals.

RunService and what-not will print it nil when accessed as-is. Workspace is special in this as it points to the Workspace instance. This only shows that you didn't run the code before replying 👀

phoriah avatar Mar 30 '23 14:03 phoriah

Ah, I didn't run the code as I was on my phone, I genuinely believed it was service only and chose to reply anyway, forgot there was a global since it's been deprecated forever so I've never used it, sorry should've checked.

image

I retract what I said then, I apologize for my baseless argument, I'll fact check myself more, thank you for pointing out.

shirovian avatar Mar 30 '23 14:03 shirovian

Adding onto this Game is affected too

print(Workspace==workspace, Game==game) --> true, true

phoriah avatar Nov 14 '23 16:11 phoriah