how do i read an array with thyme?

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

how do i read an array with thyme?

Postby cocolover76 » Wed May 11, 2011 11:08 pm

how do i read an array with thyme?
please tell me!! :!: :!:
Image
cocolover76
 
Posts: 135
Joined: Sun May 08, 2011 10:49 pm

Re: how do i read an array with thyme?

Postby electronicboy » Wed May 11, 2011 11:53 pm

reading an array is like reading any other variable but with a slight change

Code: Select all
scene.my.array(X)

Where X is, is the value in the array you are reading.
Ps, the value starts from 0

E.g. In the array, [0,1,2,3.4]
array(0) would return 0
Array(3) would return 3

If you need more help just ask :)
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: how do i read an array with thyme?

Postby cocolover76 » Thu May 12, 2011 12:30 am

i was doing
Code: Select all
e.other.text(0) == "MONITOR"?{e.this.text = e.other.text(1)} e.other.text(0) == "CLEAR"?{e.this.text = ""}

for oncollide, but it keeps changing it to
Code: Select all
e.other.text(0) == "MONITOR"(?)({e.this.text = e.other.text(1)})(e.other.text)(0) == "CLEAR"(?)({e.this.text = ""})

and it doesnt work.

so how do i fix this?? :?:
Image
cocolover76
 
Posts: 135
Joined: Sun May 08, 2011 10:49 pm

Re: how do i read an array with thyme?

Postby bozbez » Thu May 12, 2011 12:35 am

cocolover76 wrote:i was doing
Code: Select all
e.other.text(0) == "MONITOR"?{e.this.text = e.other.text(1)} e.other.text(0) == "CLEAR"?{e.this.text = ""}

for oncollide, but it keeps changing it to
Code: Select all
e.other.text(0) == "MONITOR"(?)({e.this.text = e.other.text(1)})(e.other.text)(0) == "CLEAR"(?)({e.this.text = ""})

and it doesnt work.

so how do i fix this?? :?:

Like this:
Code: Select all
e.other.text(0) == "MONITOR" ? {e.this.text = e.other.text(1)} : {e.other.text(0) == "CLEAR" ? {e.this.text = ""} : {}}

or:
Code: Select all
e.other.text(0) == "MONITOR" ? {e.this.text = e.other.text(1)} : {};
e.other.text(0) == "CLEAR" ? {e.this.text = ""} : {}
Image

Go here. Now. That's Now. Not in 5 minutes. Now.
User avatar
bozbez
 
Posts: 149
Joined: Tue Apr 12, 2011 7:01 pm

Re: how do i read an array with thyme?

Postby cocolover76 » Fri May 13, 2011 12:39 am

bozbez wrote:Like this:
Code: Select all
e.other.text(0) == "MONITOR" ? {e.this.text = e.other.text(1)} : {e.other.text(0) == "CLEAR" ? {e.this.text = ""} : {}}

or:
Code: Select all
e.other.text(0) == "MONITOR" ? {e.this.text = e.other.text(1)} : {};
e.other.text(0) == "CLEAR" ? {e.this.text = ""} : {}

I tried both ways and it still didnt work. :x :cry:

If this helps you fix it, I am using Algodoo Phun Edition v5.28
Image
cocolover76
 
Posts: 135
Joined: Sun May 08, 2011 10:49 pm

Re: how do i read an array with thyme?

Postby bozbez » Fri May 13, 2011 1:02 am

I just realised that there is a deeper problem. You can't have an array in "text". "textureMatrix" would be the one to use.
Image

Go here. Now. That's Now. Not in 5 minutes. Now.
User avatar
bozbez
 
Posts: 149
Joined: Tue Apr 12, 2011 7:01 pm

Re: how do i read an array with thyme?

Postby Someone Else » Fri May 13, 2011 3:34 am

For textureMatrix, you can only use float values, like 39.0.

And I think he's trying to reverse-engineer the AHOX computers.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: how do i read an array with thyme?

Postby cocolover76 » Sat May 14, 2011 12:47 am

Someone Else wrote:And I think he's trying to reverse-engineer the AHOX computers.


Read viewtopic.php?f=6&t=4013 . Before I release my PC, I will get permission (I already private messaged Kutis96 to ask for permission but he didn't reply yet)
EDIT: he replyed.
Last edited by cocolover76 on Tue May 24, 2011 11:33 pm, edited 1 time in total.
Image
cocolover76
 
Posts: 135
Joined: Sun May 08, 2011 10:49 pm

Re: how do i read an array with thyme?

Postby electronicboy » Sat May 14, 2011 2:27 am

I will pass a message on to kutis to check his PM over skype in the morning. well, what is morning to me :D
ps, fell free to send me a link >D

Have you managed to get the programing system working?
Kutis uses the eval command to remove the array out of the text.
I just cant remember how exactly it is used...
i mainly focus on helping with the actual programs and not the actual CPU...



------------
Electronicboy
AHOX Beta Tester and Developer <yay im now a dev (kinda) >D

yup, now im showing off with my lame fancy sig >D
yup, im in one of my crazy moods...
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: how do i read an array with thyme?

Postby Someone Else » Sat May 14, 2011 3:56 am

Hmm... I am also trying (unsuccessfully) to reverse-engineer the AHOX computers.

Maybe I will try to look at a really old version, and also fool around with eval.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: how do i read an array with thyme?

Postby cocolover76 » Sun May 15, 2011 6:03 pm

NOW, i am doing
Code: Select all
eval(e.other.text)(0) == "MONITOR" ? {e.this.text = eval(e.other.text)(1)} : {}; eval(e.other.text)(0) == "CLEAR" ? {e.this.text = ""} : {}
.
it accepted it, but it still does not work!!!!

and no, i CAN see the text if i change it in appearance so how do i fix this??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

edit: i might not post for a while and it will be a long time for me to finish typing this if i explain why.
Image
cocolover76
 
Posts: 135
Joined: Sun May 08, 2011 10:49 pm

Re: how do i read an array with thyme?

Postby bozbez » Sun May 15, 2011 6:48 pm

You're still trying to use a string as an array.
Image

Go here. Now. That's Now. Not in 5 minutes. Now.
User avatar
bozbez
 
Posts: 149
Joined: Tue Apr 12, 2011 7:01 pm

Re: how do i read an array with thyme?

Postby electronicboy » Sun May 15, 2011 10:06 pm

i think i know how to do it!

This will create a new variable on the cpu, called "program"
The program variable is where the program array will be stored.
this also presumes that the code is on the thyme CPU:

Put this code on a block collider (circles can have text)
The program will go in the text field on the collider.

e.other.program = eval(e.this.text)

This is based upon the eval code you have gave.

You will need to modify existing code in the processor.

E.g.

[code]eval(e.other.text)(0) == "MONITOR" ? {e.this.text = eval(e.other.text)(1)} : {}; eval(e.other.text)(0) == "CLEAR" ? {e.this.text = ""} : {}

Should be

[code]e.geom.program(0) == "MONITOR" ? {e.this.text = e.geom.program(1)} : {}; e.geom.program)(0) == "CLEAR" ? {e.this.text = ""} : {}

I see that the CPU is also the monitor :D
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: how do i read an array with thyme?

Postby Someone Else » Mon May 16, 2011 1:10 am

Thank You Electronicboy! It (mostly) works!

What you really want is this:
Code: Select all
e.this.program = eval(e.other.text);
{program(controllerAcc)(0) == "MONITOR"} ? {text = "" + program(controllerAcc)(1)} : {};
{program(controllerAcc)(0) == "MONITOR+"} ? {text = text + "\n" + program(controllerAcc)(1)} : {};
{program(controllerAcc)(0) == "CLEAR"} ? {text = ""} : {};
controllerAcc = controllerAcc + 1


Make sure you set controllerAcc to 0 first. That got me. Also, this is the syntax you want:

Code: Select all
[["MONITOR", "Hello"],
["MONITOR+", "World"],
["CLEAR"]]
It's an array of arrays, you need commas between commands and sections within commands. That got me, too.

I found that for this setup, you want the box with the program in its text to be fixated to a long bar, hinged to the background at the other end. The program box and the CPU should both have restitution of 1. The code box should swing into the CPU, bounce off, swing away, swing back, and strike the CPU again, performing the next opcode.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: how do i read an array with thyme?

Postby TC42 » Wed May 25, 2011 2:52 am

*bump*

I just found out that you can use code such as
Code: Select all
scene.my.array(scene.my.arrayaccess)

Instead of scene.my.array(--put integer here--)
So if scene.my.array=[2, 4, 8, 16, 32, 64], and scene.my.arrayccess = 3, the result would be 16. This will make my new project so much easier!
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: how do i read an array with thyme?

Postby Someone Else » Thu May 26, 2011 3:27 am

That's exactly how the code in the post above uses controllerAcc.

Sorry, pointless bump, you fail.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: how do i read an array with thyme?

Postby TC42 » Thu May 26, 2011 4:20 am

Well, it had a point-- It was an accurate summary of the above code for those of use (like myself) who didn't understand a word of it :P
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: how do i read an array with thyme?

Postby Someone Else » Fri May 27, 2011 12:35 am

Fine.
Whatever.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: how do i read an array with thyme?

Postby cocolover76 » Mon Aug 22, 2011 11:10 pm

I think I get it now....

Code: Select all
scene.my.program = e.other.text;
scene.my.one = scene.my.program(0);
scene.my.two = scene.my.program(1);
scene.my.three = scene.my.program(2);


So, after the above code happened, and e.other.text is:

Code: Select all
[1,2,3]


, scene.my.one would be 1, .two = 2, and .three = 3?
(I am incredbly busy, so I didn't have time to try this, sorry :()
Image
cocolover76
 
Posts: 135
Joined: Sun May 08, 2011 10:49 pm

Re: how do i read an array with thyme?

Postby electronicboy » Tue Aug 23, 2011 12:07 am

okay, firstly, the concept you have is correct, but it wont work like that (because of line one)

scene.my.program = eval{e.other.text}

Try that...

ps, if you had read the topic before posting, chances are, you wouldn't need to have bumped...
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: how do i read an array with thyme?

Postby Someone Else » Thu Aug 25, 2011 2:58 am

No, actually, it's eval(e.other.text).
Eval is a function, so the argument goes in parenthesis, not braces.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: how do i read an array with thyme?

Postby cocolover76 » Fri Sep 02, 2011 9:27 pm

Sorry, I just held Page Down to get to the Post Reply because I was in a hurry so I would post it before I forgot my idea.
Image
cocolover76
 
Posts: 135
Joined: Sun May 08, 2011 10:49 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest