Skip to content

Add ExprTimeLived #8134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: dev/feature
Choose a base branch
from
Open

Conversation

MrScopes
Copy link
Contributor

@MrScopes MrScopes commented Aug 18, 2025

Problem

There's no current way to get the time lived of an entity

Solution

Added ExprTimeLived
time lived of %entities%
%entities%'s time alive
etc

Testing Completed

Test 1

		spawn cow at player:
			set {_cow} to cow
		wait 3 seconds
		send time lived of {_cow}
		send ticks of time lived of {_cow}
		send {_cow}.getTicksLived() # tested with the direct method
		wait 2 seconds
		send time lived of {_cow}
		reset time lived of {_cow}
		send time lived of {_cow}
		wait 1 second
		set time lived of {_cow} to 3 weeks
		remove 2 weeks from time lived of {_cow}
		send time lived of {_cow}
		add 1 week to time lived of {_cow}
		send time lived of {_cow}

expected off by a tick? I'm assuming since it doesn't wait for the cow to actually "start living"?
that's the reason I added the getTicksLived directly just to make sure this wasn't an error in the expression

image

Test 2 - edited provided example

		set {_target} to player's target entity
		send "%{_target}% has lived for %time lived of {_target}%"

		set {_spawned} to now

		spawn zombie at player:
			set {_boss} to zombie
		# start off with 1 tick lived instead of 0 to avoid custom effects running off spawn
		add 1 tick to {_boss}'s time lived
		while {_boss} is alive:
			wait 1 tick
			# update display name every tick with hp
			set display name of {_boss} to "Boss %{_boss}'s health%/%{_boss}'s max health%"
			# heal every second
			if mod(ticks of {_boss}'s time lived, 20) is 0:
				broadcast "heal every second. it's been %difference between now and {_spawned}%"
				add 1 to {_boss}'s health
			# push forward every 2 seconds
			if mod(ticks of {_boss}'s time lived, 40) is 0:
				broadcast "push every 2 seconds. it's been %difference between now and {_spawned}%"
				push {_boss} forward at speed 1
			# give strength every 10 seconds
			if mod(ticks of {_boss}'s time lived, 200) is 0:
				broadcast "strength every 10 seconds. it's been %difference between now and {_spawned}%"
				add potion effect of strength for 3 seconds to {_boss}'s potion effects
image

Test 3

image

Supporting Information

No breaking changes
image
Just out of curiosity I checked back and from what I can tell even in ancient versions of the game getTicksLived and setTicksLived has stayed the same


Completes: none
Related: none

@MrScopes MrScopes requested a review from a team as a code owner August 18, 2025 16:27
@MrScopes MrScopes requested review from Pesekjak and TheMug06 and removed request for a team August 18, 2025 16:27
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label Aug 18, 2025
@Absolutionism Absolutionism added the feature Pull request adding a new feature. label Aug 18, 2025
@Absolutionism Absolutionism moved this to In Review in 2.13 Releases Aug 18, 2025
MrScopes and others added 11 commits August 18, 2025 22:28
Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
@MrScopes MrScopes requested a review from Absolutionism August 19, 2025 03:02
MrScopes and others added 2 commits August 19, 2025 21:38
Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
Copy link
Contributor

@Absolutionism Absolutionism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last one, re-request for approval

Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
@MrScopes
Copy link
Contributor Author

Last one, re-request for approval

I will add the import when I get home and run some final tests then request review

@MrScopes
Copy link
Contributor Author

Last one, re-request for approval

Import and testing done, resubmitting approval request
test results are identical as expected
image
image
as expected it can be off within .05 seconds or 1 tick

@MrScopes MrScopes requested a review from Absolutionism August 21, 2025 00:48
@github-project-automation github-project-automation bot moved this from In Review to Awaiting Merge in 2.13 Releases Aug 21, 2025

@Override
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
int newTicks = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to store this and valueToSet as longs to account for overflows. That is, if the value is set to high for an int, clamp it down to the max int value.

@skriptlang-automation skriptlang-automation bot added feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. and removed needs reviews A PR that needs additional reviews labels Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
Status: Awaiting Merge
Development

Successfully merging this pull request may close these issues.

5 participants