• Hey! Register here to create your account, engage with the community, and talk about what is new!

%{}

Ashli

Server Developer
Developer
Joined
Sep 12, 2020
Messages
112
Reaction score
26
I made a post on DFS and after some discussion involving feasibility and implementation of the original suggestion, we decided on this:



New percent code: %{}
It functions as a simplification for text codes.

Any text inside of %{} behaves differently to allow for making complex equations or functions without it becoming too messy.

Rules:
- Any text by itself will be treated as a variable. (So %{a} is the same as %var(a))
- Any text surrounded in square brackets will also be treated as a variable. (So %{[%default a]} is the same as %var(%default a))
- Any text surrounded in quotes are assumed to be a string literal, and not a variable. (%{"Hello"} is Hello)
- Numbers are assumed to be numbers. (%{5} is 5)
- Any "function" text codes (Anything but %default, %selected, etc) no longer need a % sign. (So %{round(a)} is the same as %round(%var(a)))
- %math rules apply. Numbers will be operated with +, -, *, /, and %. Strings will be concatenated with +. (%{2+5} is the same as %math(2+5))
- Any lone parenthesis will count as another %{} automatically. (So %{(2+5)/(2*5)} is the same as %{%{2+5}/%{2*5}})
- Any functions (text codes) inside %{} will treat their inputs using these rules.


Why would this be useful?
Well, looking at it, we can already do everything here with normal text codes.
The entire point of %{} is to simplify equations.
Here are some cases where code will be drastically reduced in size by this:
(Not all these % codes actually exist, just bear with me)


%sqrt(%math(%math(%var(x)-%var(dx))+%math(%var(dx)-%var(dy))))
This is basic distance formula, let's see how short it becomes:
%{sqrt((x-dx)+(y-dy))}
Wow, that's short!


There are %floor(%math(%var(maxTime)-%var(currentTime)))[/B] [B]seconds left!
This is a simple message displaying how long a game will take. Here is it using %{} syntax:
%{"There are" + floor(maxTime-currentTime) + "seconds left!"}
Shorter, but not quite the drastic change as last time.


%var(x)
This is getting a variable's value
%{x}
%{} syntax wins again!


10
This is just a constant.
%{10}
Using %{} on literally everything is likely a bad idea. In general, the longer the equation, the more effective %{} will be.


More examples:
Whenever the text is parsed, %{} is converted to whatever value is calculated inside of it.
x = 5, y = 2;
%{x} = 5;
%{x+y} = 7
%{x+y*2} = 14;
(No order of ops to be consistent with %math grrrrr)
%{(y/2)*(x+y)} = 7
%{sin(x+y)} = 0.656



So, in short:
%{} parses text inside of it differently to allow for very compact and complex text code manipulation
without going into Nested Percent Code Hell and simplifies lone %var(x)s down to %{x}s.
This would NOT replace anything, it is treated just like any other text code but has a more complex operation on its input than others.
 
Last edited:

froggy

Retired Moderator
Overlord
Joined
Sep 6, 2020
Messages
86
Reaction score
34
would love to see this, especially since it acts way more like a normal coding language this way.
 

pixlii

Forum adept
Overlord
Joined
May 20, 2021
Messages
226
Reaction score
34
look at any df plot and you will see SO MANY "set variable" blocks. this would both shorten the amount of those, and shorten the already-existing text codes.
 
Top Bottom