Copy/pasting coded objects to behavior


#1

Hey folks,

So the vision I’m trying to do:

  • I have a person who is programmed to move forward.
  • If I duplicate the object in Cospaces, only the first instance of that person will move. The second instance of person will not move.

Question: Is there an efficient way to copy/paste an object in Cospaces so it retains it’s programming without using groups?

I understand that I can group together objects and apply code to that but I’m hoping to see if there are any other options for this. Like, if I’d want to program a bat to fly around, I’d want that bat to not be grouped so it’s rotation values are based on each individual bat, not the averaged rotation point of the group. I’ve considered using lists for example. Is it possible to get a list of every instance of an object and then apply code to that list in Cospaces?

Thanks for the help!


Duplicating 'on activate' behaviour for objects
#2

Hi Peter,

I think your idea should work. Creating a list of objects and then iterate over this list using a loop. There you can apply the code you want to each object in the list.

After that you can still add elements to the list anytime.

list2

Actually I’m not sure if you want to use JavaScript as well. There you have even more possibilities to create many instances using classes or constructor functions and so on. I can give you examples if you’re interested.


#3

Oh awesome! Yeah, I was wondering how to get a list with a foreach loop working and this seems like a great way of doing it. I’ll pass on the Javascript example but that’s good to know it’s an option.


#4

We’re also working on something called “Smart Items”. Those are basically objects with encapsulated code and when you copy the object, you copy the attached functionality as well. This will be a more convenient solution.