Thyme: Writing to array elements
9 posts • Page 1 of 1
Thyme: Writing to array elements
This may have already been suggested, but it's a MAJOR important issue as far as I'm concerned. I suggested it in the Thyme Scripting forum a few months ago, but I wanted it to also be addressed here in the Suggestions forum. Anyhow, the ability to do Array(n) = n.n is a no-brainer for any programming language that provides the ability to work with arrays. Thyme lets you READ a single array element, but it does not let you write to it (unless you include ALL array elements in the addition). Karatebrot devised an ingenious function for writing to individual array elements, and it works like a dream (see: viewtopic.php?f=13&t=1503&p=15848&hilit=writing+to+arrays#p15848 ) But Thyme should have a built-in "intrinsic" function that allows it. I read in another post where someone mentioned that Thyme updates have a low priority. Well, when the developers finally do get around to updating Thyme, I surely hope that THIS particular suggestion gets a HIGH priority!
Thanks!
Thanks!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Thyme: Writing to array elements
with the new b13 addition of editing vel and pos without hassle, i really needed to be able to edit only the x or y axis.
These are stored together in an Array, and it would be really helpfull to be able to edit them easily.
I vote for this suggestion
These are stored together in an Array, and it would be really helpfull to be able to edit them easily.
I vote for this suggestion
Basically, there are only 10 types of people in the world. Those who know binary, and those who don't.
Light travels faster than sound. That's why some people appear bright until they open their mouths.
Light travels faster than sound. That's why some people appear bright until they open their mouths.
-
monstertje3 - Posts: 343
- Joined: Sat Sep 05, 2009 4:29 pm
- Location: N-H, NL
Re: Thyme: Writing to array elements
I think we have wanted this feature for years...
You could try this function as a replacement for now:
array - variable you want to edit, e.g. scene.my.array
size - Size of the array
ind - index, the position in the array of what variable you want to replace
data - what you want to add
You could try this function as a replacement for now:
- Code: Select all
(array, size, ind, data)=>{
out1 = [];
out2 = [];
out = 1;
for(size, (n)=>{n == ind ? {out = 2} : {out == 1 ? {out1 = out1 ++ [n]} : {out2 = out2 ++ [n]}}});
array(out1) ++ [data] ++ array(out2)
}
array - variable you want to edit, e.g. scene.my.array
size - Size of the array
ind - index, the position in the array of what variable you want to replace
data - what you want to add
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Thyme: Writing to array elements
electronicboy -- Could you please give an example of how that function would be used? For the example, let's say that I want to write 3.14 to scene.my.array(47).
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Thyme: Writing to array elements
- Code: Select all
scene.my.editarray = (array, size, ind, data)=>{
out1 = [];
out2 = [];
out = 1;
for(size, (n)=>{n == ind ? {out = 2} : {out == 1 ? {out1 = out1 ++ [n]} : {out2 = out2 ++ [n]}}});
array(out1) ++ [data] ++ array(out2)
}
say, array has 50 values
- Code: Select all
scene.my.editarray(scene.my.array, 50, 47, 3.14)
I'm sure that will be the correct usage, I can't exactly say that is 100% correct, but that will be atleast similar to actual usage!
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Thyme: Writing to array elements
electronicboy wrote:I'm sure that will be the correct usage, I can't exactly say that is 100% correct, but that will be atleast similar to actual usage!
Not quite.... I played around with it, and this is what works:
- Code: Select all
scene.my.array = scene.my.editarray(scene.my.array, 50, 47, 3.14)
Thanks again!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Thyme: Writing to array elements
since we have string.length(), no need to know array size
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: Thyme: Writing to array elements
another trick if you know exactly size and element - use list mult and sum:
example:
a = [1,2,3,4,5]
if you need to change a(0) to some value X:
a = a * [0,1,1,1,1] + [X,0,0,0,0]
example:
a = [1,2,3,4,5]
if you need to change a(0) to some value X:
a = a * [0,1,1,1,1] + [X,0,0,0,0]
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: Thyme: Writing to array elements
Kilinich wrote:another trick if you know exactly size and element - use list mult and sum:
example:
a = [1,2,3,4,5]
if you need to change a(0) to some value X:
a = a * [0,1,1,1,1] + [X,0,0,0,0]
Not very practical if your array is large.
EDIT: Also, you do not need to do the multiply. This works too:
- Code: Select all
a = a + [X,0,0,0,0]
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
9 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 7 guests