ID:2498542
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Like this (THIS IS EXAMPLE):
var/list/L = list("CAT", "DOG", "GOAT")
world << L[-1]//Must output "GOAT" in world
world << L[-2]//Must output "DOG" in world.
world << L[-4]//Must be runtimed or index start from end second time, so we have two branches, it runtiming or it will return "GOAT"


Workaround:
world << L[length(L)]//Must output "GOAT" in world
world << L[length(L) - 1]//Must output "DOG" in world.

or
L[L.len]
L[abs(-2)]
gg
Which works for exactly 1 element in the entire list.
In response to Kozuma3
Kozuma3 wrote:
L[abs(-2)]
gg

This code is an example, i needn't your crutches for this.
And it will get element with index 2 not -2, what will you do (using abs()) when length of list will be 4 or more? [-2] and [2] won't be equal.
The correct workaround for L[-n] is L.len - abs(n) + 1.
In response to MisterPerson
MisterPerson wrote:
The correct workaround for L[-n] is L.len - abs(n) + 1.

Just explain me why it and how it will get element from end
var list/l = list(
"Cat","Dog","Goat","Pig"
)



mob/Login()
var n = -2
src << l[l.len-abs(n)+1]
// l.len = 4
// abs(-2) = 2
// (4 - 2) = 2 + 1 = 3
I do think there's value in this feature, especially since a lot of the string manipulation procs take negative indices.
In response to Kozuma3
Kozuma3 wrote:
var list/l = list(
> "Cat","Dog","Goat","Pig"
> )
>
>
>
> mob/Login()
> var n = -2
> src << l[l.len-abs(n)+1]
> // l.len = 4
> // abs(-2) = 2
> // (4 - 2) = 2 + 1 = 3

Why all of you creating
not optimized, silly workaround, when i showed you optimized, small workaround?
In response to MisterPerson
MisterPerson wrote:
I do think there's value in this feature, especially since a lot of the string manipulation procs take negative indices.

Like copytext(text, -1, -6), yeah?

Login to reply.