Skip to content
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

Fix variable names with numbers containing leading zeros #3929

Conversation

TPGamesNL
Copy link
Member

Description

Fixes the variable name comparator, which used to return 0 when comparing 01 and 1, which indicates that 01 = 1, which shouldn't be in strings.
The current implementation puts 01 before 1:

command /test:
	trigger:
		set {_l::01} to "01"
		set {_l::1} to "1"
		set {_l::2} to "2"
		loop {_l::*}:
			message loop-index

returns

01
1
2

If you think it'd be better the other way around, lmk


Target Minecraft Versions: any
Requirements: none
Related Issues: #3903

@TPGamesNL TPGamesNL added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. 2.5 labels Apr 27, 2021
@TPGamesNL
Copy link
Member Author

TPGamesNL commented Apr 27, 2021

Removed the comment on negative numbers, since they are already handled correctly: since - comes before any digit, any comparison between a - and a digit will result in the variable with - being less.
Edit: nvm they're aren't handled properly yet (two negative numbers), will deal with that

@TPGamesNL
Copy link
Member Author

TPGamesNL commented Apr 28, 2021

It works properly now, negative numbers (integers or decimal numbers) are properly ordered:

command /test:
	trigger:
		loop 50 times:
			set {_i} to ((loop-number) - 25) / 10
			set {_l::%{_i}%} to "%{_i}%"
		loop {_l::*}:
			broadcast loop-index
Output
  • -2.4
  • -2.3
  • -2.2
  • -2.1
  • -2
  • -1.9
  • -1.8
  • -1.7
  • -1.6
  • -1.5
  • -1.4
  • -1.3
  • -1.2
  • -1.1
  • -1
  • -0.9
  • -0.8
  • -0.7
  • -0.6
  • -0.5
  • -0.4
  • -0.3
  • -0.2
  • -0.1
  • 0
  • 0.1
  • 0.2
  • 0.3
  • 0.4
  • 0.5
  • 0.6
  • 0.7
  • 0.8
  • 0.9
  • 1
  • 1.1
  • 1.2
  • 1.3
  • 1.4
  • 1.5
  • 1.6
  • 1.7
  • 1.8
  • 1.9
  • 2
  • 2.1
  • 2.2
  • 2.3
  • 2.4
  • 2.5

The change also affects variables without numbers, because {_l::aa} used to come before {_l::a}, which I inverted

@FranKusmiruk FranKusmiruk merged commit 2085c49 into SkriptLang:master May 4, 2021
@TPGamesNL TPGamesNL deleted the fix/numerical-index-with-leading-zeros branch May 4, 2021 06:49
@TheLimeGlass TheLimeGlass added completed The issue has been fully resolved and the change will be in the next Skript update. and removed completed The issue has been fully resolved and the change will be in the next Skript update. labels Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants