Present Vs. Past Variables

Is it possible to set a variable once a condition has occurred, and not while the condition is occurring? For example:



if localplayer:Health() >= 0 then
    playerIsAlive = true
end

if playerIsAlive then
    print("You have been alive at some point in your existance.")
end


This will print only if the player is presently alive, but will not print if the player has been alive at some point in their existance.

The underlined statement, while not directly pertaining to the conditions with which I am working, is the essential statement I am looking to code; they key clause being “at some point”.

Thanks!

i’m not sure if i understand this 100%, but
in general i’d do something like this



local var
if condition then
	if not var then
		var = true
		doSomething()
	end
else
	var = nil
end


Not quite. In simple english the statement would look like: **Once **the **condition **has occurred the **variable **becomes true.

A variable is stored and set whenever you do “variable = X”. If you need to only have this variable describe if it has ever occurred, you will just need to never change it back to false ever again. Any time you now reference this variable, it will still be true from when you set it. Now to make the variable true once a certain condition is met would use events or hooks, which one completely depends on the condition.

For an example, if you want to know if a player has ever been alive, it would probably be a good idea to hook onto PlayerSpawn or PlayerInitialSpawn and set this variable to true. Never set it to false again. If you need to know if a player has ever had X weapon, hook onto WeaponEquip and check if the weapon is X, then set the variable. Never set it to false again.

Also the example code you have given will actually print that even if the player is currently dead, given that the first part was called when the player was alive, and the if statement later when he is dead.
[lua]-- This part run some time when he is alive
localplayer:Health() >= 0 then
playerIsAlive = true
end

– This part run later when he is dead, or really any condition
if playerIsAlive then
print(“You have been alive at some point in your existance.”)
end[/lua]

that’s what my thing does, except, if called continually, it resets when the condition turns false
here’s a permanent version



local var
if not var then
	var = true
	doSomething()
end