creating variables with for-loop (ascending number)
4 posts • Page 1 of 1
creating variables with for-loop (ascending number)
Hi there!
At first, this is my context of code:
So, now the problem:
is the part where i would like to have something like this:
and of course i know that's not how it works. I actually don't know if it can be done at all. In the end there should exist (for this example 54) some variables, named with ascending numbers at the end of their name.
Could anybody tell me if it is possible and if not if there is an easy workaround because i found none (besides of creating the lasers and then go into every single script menue and typing in the variables by hand which reaaally annoys and is prone to typos). Please help! Thanks in advance!
At first, this is my context of code:
- Code: Select all
p=(-1);
q=0;
x=54; //Gesamtmenge
y=9; //Zeilen, Spalten => x/y
offset=[0,0];
for(x, (i)=>{
math.mod(i,y) == 0 ? {p = p+1; q=0}:{p = p; q = q+1};
Scene.addLaserPen({
pos:=[p,q]+offset;
fadeDist:=10;
colorHSVA:=[(i*5), 1.0, 1.0, 1.0];
buttonDestroy:="f";
size:=0.5;
maxRays:=1;
rotation:=math.pi;
onLaserHit:=(e)=>{scene.my.perceptron=e.other.colorHSVA(2)};
});
})
So, now the problem:
- Code: Select all
onLaserHit:=(e)=>{scene.my.test = something};
is the part where i would like to have something like this:
- Code: Select all
onLaserHit:=(e)=>{scene.my.test {i} = something};
and of course i know that's not how it works. I actually don't know if it can be done at all. In the end there should exist (for this example 54) some variables, named with ascending numbers at the end of their name.
- Code: Select all
scene.my.test0 = something;
scene.my.test1 = something;
scene.my.test2 = something;
scene.my.test3 = something;
...
Could anybody tell me if it is possible and if not if there is an easy workaround because i found none (besides of creating the lasers and then go into every single script menue and typing in the variables by hand which reaaally annoys and is prone to typos). Please help! Thanks in advance!
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
- hiltropper
- Posts: 85
- Joined: Mon Dec 20, 2010 12:02 pm
- Location: Germany
Re: creating variables with for-loop (ascending number)
I think you can create lists like so:
access element with:
or a range
to get length use:
There is a list append operator you can use:
If you want anything else you need to implement your own functions.
- Code: Select all
test = [something, something1, something2]
access element with:
- Code: Select all
test(0)
or a range
- Code: Select all
test(0..2)
to get length use:
- Code: Select all
string.length(test)
There is a list append operator you can use:
- Code: Select all
test = test ++ [something3]
If you want anything else you need to implement your own functions.
Spoiler: show
.
-
icrls984 - Posts: 80
- Joined: Thu Jun 13, 2013 6:33 am
Re: creating variables with for-loop (ascending number)
hiltropper -- Sounds like you need a way to write to a single array element. If that's the case, then check out the following discussion between myself and other users. You will see 2 or 3 different ideas for writing to or changing the value of a single array element:
viewtopic.php?f=13&t=12152&start=0
viewtopic.php?f=13&t=12152&start=0
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: creating variables with for-loop (ascending number)
Thanks for the replies, glad this forum ain't dead though your suggestions are not quite what i thought of, they have given me some ideas for workarounds.
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
- hiltropper
- Posts: 85
- Joined: Mon Dec 20, 2010 12:02 pm
- Location: Germany
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests