-
Notifications
You must be signed in to change notification settings - Fork 2
Getting started | Local player variables
While global variables are useful, they can sometimes lead to unexpected behavior in your scripts. Local player variables offer more control and predictability, making your scripts more robust.
- They hold a snapshot of players provided. They won't automatically update, even when made from a global variable.
- They're accessible only in the script in which they were created.
- You can freely add or remove players from them.
Important
- Variable name must start with a lowercase letter
- Variable name can only be made up of letters and numbers
✅ @myPlayers
✅ @scp999
❌ @Idiot
❌ @999
❌ @i_love_vars
@myLocalVar = @scpPlayers
This will create @myLocalVar with the same players that @scpPlayers has in that moment!
@myLocalVar = ()
Useful for adding players manually using a custom system.
@myLocalVar = JoinPlayers @classDPlayers @scientistPlayers
This will get the player value from the JoinPlayers method.
Note
The use of methods as values will be explained later down the tutorial series. Don't worry about it for now, we will be coming back to this.
GiveItem @scpPlayers Radio
Wait 1s
❗ DestroyItem @scpPlayers Radio
The issue presented here, where @scpPlayers can change its value because of the Wait 1s method can be remedied with local variables.
@playersGivenRadio = @scpPlayers
GiveItem @playersGivenRadio Radio
Wait 1s
👍 DestroyItem @playersGivenRadio Radio
Now that we use the @playersGivenRadio variable, we are certain that all radios will be removed from player inventories.
If you want to get all players from a room, e.g. EzGateA, you will need to check every single player's current room, and add them to your local variable accordingly.
@gateAPlayers = ()
for @plr in @allPlayers
{*room} = Get @plr room
if ({*room} == UNDEFINED)
continue
end
{roomName} = RoomInfo {*room} name
if ({roomName} != EzGateA)
continue
end
@gateAPlayers = JoinPlayers @gateAPlayers @plr
end
In short, we have an empty variable called @gateAPlayers and we add players to that variable if their current room is EzGateA.
Note
The use of loops, conditions, literal variables and object references will be explained later down the tutorial series. Don't worry about it for now, we will be coming back to this.
(These tutorials are ordered, start from the top)