Scrap the first value of a n-length array
4 posts • Page 1 of 1
Scrap the first value of a n-length array
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
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
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
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
Dream of Algodoo as game development engine...
-
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
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
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
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests