Get array of selected entities

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

Get array of selected entities

Postby nomcycle » Sat Aug 08, 2015 8:17 am

Hi all!

I am new to Algodoo and and the community. I find the program fascinating. I have a lot of experience in game programming. But I am new to Thyme, and its language. I have found the tutorials and references pinned to this forum. But I have some questions.

Here is my first question: How can I acquire an array of entities via selection?

Thanks!
nomcycle
 
Posts: 3
Joined: Sat Aug 08, 2015 8:08 am

Re: Get array of selected entities

Postby FRA32 » Sat Aug 08, 2015 5:38 pm

You mean the code data of some entities in the scene to use them as scene.add[something] ?

Select all the shapes you need the data of, press copy, and then insert it into some text editor. Delete the beginning with fileInfo and phunlet, so that the first thing is a scene.addsomething command. Then you can seperate each add command and edit their attributes if you want. I recommend removing the Body attribute before adding the code again, as you end up with glued shapes otherwise
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: Get array of selected entities

Postby nomcycle » Sat Aug 08, 2015 6:01 pm

Ok thanks, that's pretty cool. Although I am trying something a little different.

Lets say I want to write a script that modifies the parameters of existing entities in the scene. Specifically the entities that I have selected in the scene. Is there a way to access an array of spawned entities or an array of selected entities?

I know you can store an entity into a variable by calling "Scene.entityByID". But I want to store an entity into a variable without having to find it's ID.
nomcycle
 
Posts: 3
Joined: Sat Aug 08, 2015 8:08 am

Re: Get array of selected entities

Postby homieeee » Sat Aug 08, 2015 11:23 pm

If you want to get all the entityID's from a selection all you have to do is select them go to script menu and paste "scene.my.stuff = scene.my.stuff ++ [entityid]" into the menu. This will create the variable scene.my.stuff as a list with all the id's.

ID's are in random order

If you want the list to be there every time the scene starts then select all the entities you want and put "scene.my.stuff = scene.my.stuff ++ [entityid]" into the "onspawn" in their script menu.

This list will be organized from oldest object to newest. (ID's are in ascending order)

Any other questions just ask.
User avatar
homieeee
 
Posts: 14
Joined: Thu Oct 09, 2014 2:13 am

Re: Get array of selected entities

Postby nomcycle » Sun Aug 09, 2015 8:23 pm

That worked pretty well, thanks.
nomcycle
 
Posts: 3
Joined: Sat Aug 08, 2015 8:08 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests