Creative+ How to code Offline Variables

AgentFizz

New member
Joined
Jun 22, 2023
Messages
2

Offline Player Variables

This post will only explain the basics and the main code. Use your creativity to code whatever you want to use this mechanic for.
|----------------------------------------------------------------------------------------------------------------|​

What are Offline variables?

Well, as the name suggests, offline variables are variables of an offline player.

How do we modify Offline Variables?
Before we move on to this topic, let us understand more about Player Variables.

|----------------------------------------------------------------------------------------------------------------|​

How do player variables work?

If you noticed, we often use the placeholder "%player%" or "%selected%". Do you know what it does? It simply returns the name of the player that triggered the event or returns the selected players.

Now, if you create/modify a variable " %player% joins " whenever a player joins, then %player% will be the name of the player that joined.

For example, A player "Fizz" joins the game. His variable will be " Fizz joins" (%player% joins).


If you have worked with entities before, then you know that when we select an entity with a certain name, and use the placeholder %selected%, it returns the entity's name.

Compare the following variables:

1. An entity with the name "Fizz" is selected. Now we set a certain variable for this entity

(%selected% joins) | which, when outputted, will become (Fizz joins)

2. A player with the name "Fizz" is selected/triggered an event. Now we set a certain variable for this player.

(%player% joins) | which, when outputted, will become (Fizz joins).


Do you notice a similarity?

Both the variables are, in fact, the same!

So, when we modify the variable of the entity, we also modify the variable of the player. We can use this mechanic to our advantage and code Offline Player Variables.

|----------------------------------------------------------------------------------------------------------------|

How to modify Offline Variables?

Now that you understand the concept, we can begin coding.

Spoon-feeding is not good, so I'll just explain the main thing and you'll try to code it yourself (with understanding). (Trust me, you'll find great satisfaction when you code this on your own)

Here's what we want to do:

1. Spawn an entity for the whole game
2. Whenever needed, get the entity using it's location
3. Select that entity
4. Change it's name (using "Player Action --> Parameters)
5. Use the %selected% placeholder in variables
6. Remove the entity if need be

So, here's the flow

Consider the entity spawned and the code is in a particular event...
Select Entity (Select Object) --> Change Name (to the player's exact name) (Player Action) --> Modify variables using %selected% (Set Variables)

|----------------------------------------------------------------------------------------------------------------|​

If you do not understand, reply to this post and I'll see whatever I can do to help you out.
 
Last edited:
Top