Variable in an identifier??
			6 posts			 • Page 1 of 1		
	
Variable in an identifier??
How can I declare a new variable that its identifier contains a variable??
I want something like this to create n number of array like scene.my.brain(n).
			
		I want something like this to create n number of array like scene.my.brain(n).
- Code: Select all
 scene.my.count1 >= 20 ? {} :
{
scene.my.brain(scene.my.count):=
[
scene.my.random,
scene.my.random,
scene.my.random,
.....
.....
scene.my.random,
scene.my.random,
scene.my.random,
0
]
;scene.my.count1 = scene.my.count1 + 1
}
- Antotabo
 - Posts: 54
 - Joined: Tue Sep 01, 2009 6:27 am
 
Re: Variable in an identifier??
in thyme you have to give arrays the values of all array elements at the same time (its stupid like that) but there are ways around it - eval command parses text into code so you could either do something like
scene.my.codebuffer="scene.my.brain:=[
for (20, (n)=>{
scene.my.codebuffer=scene.my.codebuffer+scene.my.random+", "
<swap random here>
})
scene.my.codebuffer=scene.my.codebuffer+"]"
eval(scene.my.codebuffer)
or a much easyer solution would be just to make a buttload of dynamically numerated variables, that way you can also easily add or change them later
for (20, (n)=>{
eval("scene.my.brain"+n+":="+scene.my.random")
<swap random here>
})
PS! untested code, might detonate your computer
			
		scene.my.codebuffer="scene.my.brain:=[
for (20, (n)=>{
scene.my.codebuffer=scene.my.codebuffer+scene.my.random+", "
<swap random here>
})
scene.my.codebuffer=scene.my.codebuffer+"]"
eval(scene.my.codebuffer)
or a much easyer solution would be just to make a buttload of dynamically numerated variables, that way you can also easily add or change them later
for (20, (n)=>{
eval("scene.my.brain"+n+":="+scene.my.random")
<swap random here>
})
PS! untested code, might detonate your computer
- Mr_Stabby
 - Posts: 155
 - Joined: Wed Dec 16, 2009 12:16 am
 
Re: Variable in an identifier??
Yeah, I know that you CAN'T write only one data at a time like this : 
But what I mean is that I want to create several arrays like that:
The elements in the arrays are created in a single command like my original post and I know this works:
Then elements of those arrays are loaded on normal variables to be read and edited, then stored back all at one time into the proper array. Like this:
Load code:
Write code:
But what I mean is how can I create/read/write on those arrays using a variable to define which array I want to read/write/create. In other words, what can replace the number contain in this : scene.my.brain1
by this: scene.my.count?
Thanks!
			
		- Code: Select all
 scene.my.brain1(0)=scene.my.random
But what I mean is that I want to create several arrays like that:
- Code: Select all
 scene.my.brain1, scene.my.brain2, scene.my.brain3...
The elements in the arrays are created in a single command like my original post and I know this works:
- Code: Select all
 (event):...
{scene.my.brain1:=
[
scene.my.random,
scene.my.random,
.....
.....
scene.my.random,
scene.my.random,
0
]}
Then elements of those arrays are loaded on normal variables to be read and edited, then stored back all at one time into the proper array. Like this:
Load code:
- Code: Select all
 scene.my.a1=scene.my.brain3(0); scene.my.a2=scene.my.brain3(1)...scene.my.d4=scene.my.brain3(7)....
Write code:
- Code: Select all
 scene.my.brain3=[scene.my.a1,scene.my.a2,...scene.my.d4...]
But what I mean is how can I create/read/write on those arrays using a variable to define which array I want to read/write/create. In other words, what can replace the number contain in this : scene.my.brain1
by this: scene.my.count?
Thanks!
- Antotabo
 - Posts: 54
 - Joined: Tue Sep 01, 2009 6:27 am
 
Re: Variable in an identifier??
i still dont get what ur trying to do but i think whatever it is can be solved by jagged arrays
array = [[a, b], [c, d]]
as result
array(0) = [a, b]
array(1) = [c, d]
array(0)(0) = a
array(0)(1) = b
array(1)(0) = c
array(1)(1) = d
you can make it as big and/or wide as you like
or you could make fake pointer array to arrays like this
pointerarray=["arrayname1", "arrayname2"]
value=eval(pointerarray(n)+"("+n2+")")
or make it a pointer array to pointer arrays that point to regular variables which is even more confusing but actually much more efficent and flexible then jagged arrays while performing the same task
			
		array = [[a, b], [c, d]]
as result
array(0) = [a, b]
array(1) = [c, d]
array(0)(0) = a
array(0)(1) = b
array(1)(0) = c
array(1)(1) = d
you can make it as big and/or wide as you like
or you could make fake pointer array to arrays like this
pointerarray=["arrayname1", "arrayname2"]
value=eval(pointerarray(n)+"("+n2+")")
or make it a pointer array to pointer arrays that point to regular variables which is even more confusing but actually much more efficent and flexible then jagged arrays while performing the same task
- Mr_Stabby
 - Posts: 155
 - Joined: Wed Dec 16, 2009 12:16 am
 
Re: Variable in an identifier??
Sorry for the bump, but I just want to know a simple thing because I don't understand MR_Stabby first response.
How can I create an array in which the name of it contains a number of an existing variable.
Let me explain:
I have a variable that increment by one each time the code is run:
scene.my.count
I want to create a new array each time the code run:
scene.my.array**the variable contained inscene.my.count should be here**:= [0,0,0...]
How can I do that? Is it just a matter of using the right () [] " " at the right place?? tell me please!
Thanks to Mr_graddy for your help.
			
		How can I create an array in which the name of it contains a number of an existing variable.
Let me explain:
I have a variable that increment by one each time the code is run:
scene.my.count
I want to create a new array each time the code run:
scene.my.array**the variable contained inscene.my.count should be here**:= [0,0,0...]
How can I do that? Is it just a matter of using the right () [] " " at the right place?? tell me please!
Thanks to Mr_graddy for your help.
- Antotabo
 - Posts: 54
 - Joined: Tue Sep 01, 2009 6:27 am
 
Re: Variable in an identifier??
OK sorry, I found It!
			
		- Code: Select all
 scene.my.count1 <= 20 ? { eval("scene.my.brain" + scene.my.count1 + ":=[scene.my.random, scene.my.random,...... scene.my.random,0]"); scene.my.count1 = scene.my.count1 + 1 }
- Antotabo
 - Posts: 54
 - Joined: Tue Sep 01, 2009 6:27 am
 
			6 posts			 • Page 1 of 1		
	Who is online
Users browsing this forum: No registered users and 5 guests



