Open Helianthella opened 7 years ago
Something that would be great is multidimensional arrays. Is it possible to make with the current script engine?
@Murilo-BiO
eventInfo = [
"reward": [
"id": Apple,
"amount": 20
]
];
@Ridley8819 sent an example that I made in a conversation about changes in script engine, I suggested the multidimensional arrays with more readable keys like in PHP arrays
I'm going to have to disagree on most due to lack of flexibility or unnecessary processing for simple function calls. I strongly believe that code should be easily understandable. Some of the syntaxes such as ...
imply "magic" happening. There is no magic in code (so to speak).
Might I suggest considering the following -
.@var = [1, 2, 3, 4, 5];
for setarray .@var[0], 1, 2, 3, 4, 5;
.
and so if ever implementing multi-dimensional arrays, we could have the following variant(s) -
.@var = [ [1, 2], [3, 4], [5, 0]];
and so on.
as for the math shorthand method, the python syntax is ok.
If add brackets, better add it like in C. this mean
.@var = {1, 2, 3, 4, 5};
.@var = {{1, 2}, {3, 4}}
@Smokexyz
Some of the syntaxes such as
...
imply "magic" happening. There is no magic in code (so to speak).
and yet many languages use this:
(and so on)
@mekolat by magic I meant in your example you use 3 dots for assigning to a variable -
.@var = 1...5;
and also passing each index by value to another .@var = ...#var2;
well we could drop the range one (1...5
) so that it's only ever used for arrays
@mekolat Sounds good to me 👍
I really like these ideas, especially the array and math shorthands. Destructuring seems quite dangerous, especially given the current state of things with the script engine, so I'd refrain for now (at least until parentheses are mandatory in function calls, and perhaps variables need to be declared).
I give my approval for:
.@var = {1, 2, 3, 4, 5};
.@var = {1 .. 5};
(either two or three dots as long as there's an agreement, but I think it should be surrounded by braces)5 ** 2
I'm not sure about the copyarray shorthand right now. We could consider delaying it to after we remove the use of all those weird .@var
, ##var
, $@var
sigils (so maybe at that point we can even use @array
to refer to the whole array).
Note that the parser isn't very friendly, and likely contains bugs, especially around parenthesized expressions and the if() conditional, so I recommend caution.
We could consider delaying it to after we remove the use of all those weird
.@var
,##var
,$@var
sigils (so maybe at that point we can even use@array
to refer to the whole array).
Instead of pretty much rewriting the script engine why not switch to AngelScript or Lua altogether?
If I were to pick a replacement language, I'd have gone for a sane, widely used language, such as ruby (1.8%), perl (2.2%), python (4.5%), not some exotic language with a very small market share and little support and resources (lua 0.6%; squirrel not in the top 100, angelscript not in the top 100). (note: figures from the TIOBE index, based on the most popular search engines)
@mekolat -> @MishimaHaruna Haru said this on #845
if you want something simple then yeah python makes sense, or even javascript (if we add nodejs bindings)
I wanna hear your thoughts before I start implementing some script shorthands so we can all agree on the syntax first.
array shorthand methods
.@var = {1, 2, 3, 4, 5};
setarray(.@var[0], 1, 2, 3, 4, 5);
.@var += {1, 2, 3, 4, 5};
setarray(.@var[getarraysize(.@var)], 1, 2, 3, 4, 5);
.@var = {1 .. 5};
setarray(.@var[0], 1, 2, 3, 4, 5);
.@var = {1 ... 5};
setarray(.@var[0], 1, 2, 3, 4);
math shorthand methods
5 ** 2
pow(5, 2)
old proposal (click here)
### array shorthand methods * `.@var = 1, 2, 3, 4, 5;` * shorthand for `setarray .@var[0], 1, 2, 3, 4, 5;` * `.@var = 1...5;` * shorthand for `setarray .@var[0], 1, 2, 3, 4, 5;` * `.@var = ...#var2;` * passes every element of `#var2` as an argument to the array shorthand method * shorthand for `copyarray(.@var[0], #var[0], getarraysize(#var[0]));` * `some_buildin(...array);` * passes every element of `array` as arguments to `some_buildin` ### destructuring * `.@a, .@b, .@c = .@d, .@e, .@f;` * shorthand for `.@a = .@d; .@b = .@e; .@c = .@f;` * `.@a, .@b, .@c = ....@d;` * shorthand for `.@a = .@d[0]; .@b = .@d[1]; .@c = .@d[2];` ### math shorthand methods * `5 ** 2` * shorthand for `pow(5, 2)`