![]() |
Array Slicing
This is probably a bit of a large request because it involves the syntax of the language itself, but having slicing syntax similar to that of Python would be really useful.
For example: PHP Code:
Really, better support for treating strings as arrays in general would be nice. |
what's wrong with using substring and subarray?
I guess this is just to make code shorter. |
Yeah. This just looks like an alternative substring() syntax...
|
It's not different, my point is it's cleaner and shorter. Which is important.
|
Quote:
|
Hey look, it's another "this other language does this better so let's put it in GS2" thread!
|
Quote:
|
Personally, I just wish GS2's substring supported something like string.substring(-1) which would take off 1 character from the back of the string, rather than having to write out: string.substring(0, string.length() - 1)
|
That alone would be a very nice addition.
|
Quote:
|
Quote:
Different languages have different ways of doing things. Python has this syntax. PHP has the array_slice() and substr() functions. GS2 has .subarray() and .substring(). Quote:
|
You have a point, although I think it wouldn't be quite that much of a problem for new scripters. In any case, what Tig said I think is a pretty reasonable suggestion, and not hard to add in.
|
Quote:
Quote:
|
In Graal script we tried to prevent any confusion. Operators only have one meaning, that's why there is @ and + for strings and numbers, instead of using + for both. The array operator should also stay like it is, the tiles[x,y] syntax can already be confusing enough.
The substring(-1) extension could be interesting, although I'm not sure if it would break some scripts that accidently go below 0 for the index? |
Well, I personally think if their script is accidentally searching for an index below 0 that it's their own fault anyways, but in that case you could use substring(0,-1), or something like that.
|
| All times are GMT +2. The time now is 04:12 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.