Scrap the first value of a n-length array

About advanced scenes, and the Thyme scripting language used in Algodoo.

Scrap the first value of a n-length array

Postby The Linkage » Wed Feb 22, 2017 11:49 pm

Hello, I need some help with an array script over here. I have an array of n values (let's say, 50) to which I need to delete the first value every step and add one through ++. The system works like I did it right now, this way:
First I have a script that adds a new value every step, like _array = _array ++ [vel] for example.
At the same time I check if the array's string.length is bigger than 49, and if that is true rewrite the array like
Code: Select all
_array = [_array(1), _array(2), _array(3)...]

The obvious problem to this approach is how huge the code is. Right now I'm only using 19 values so it's no big deal, but I want to make the length easily changeable.

So to make it simpler, I need to transform an array like [2.2, 5.1, 8.3, 5.9, 4.2, 2.1] to [5.1, 8.3, 5.9, 4.2, 2.1] with compatibility for any array length, at least until 50 values
The Linkage
 
Posts: 57
Joined: Fri Aug 05, 2011 5:40 pm
Location: Escobar, Argentina

Re: Scrap the first value of a n-length array

Postby The Linkage » Thu Feb 23, 2017 12:35 am

EDIT - whatever, got it working nicely now. If anyone else is interested, the code is

Code: Select all
killFirst = (v)=>{
    array := [];
    for(string.length(v) - 1, (i)=>{
        array = array ++ [v(i + 1)]
    });
    array
}
The Linkage
 
Posts: 57
Joined: Fri Aug 05, 2011 5:40 pm
Location: Escobar, Argentina

Re: Scrap the first value of a n-length array

Postby Kilinich » Thu Feb 23, 2017 10:04 am

use XFor instead of for. Code is here:

viewtopic.php?f=13&t=5146&start=0
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Scrap the first value of a n-length array

Postby The Linkage » Thu Feb 23, 2017 7:58 pm

That's much better, thanks.
I think I won't use this anyways, but i'll keep it as a phunlet if the need arises
The Linkage
 
Posts: 57
Joined: Fri Aug 05, 2011 5:40 pm
Location: Escobar, Argentina


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 10 guests