Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   The Lounge (http://www.alice.org/community/forumdisplay.php?f=4)
-   -   Runtime Object Creation (http://www.alice.org/community/showthread.php?t=8464)

arty-fishL 05-04-2012 09:21 AM

Runtime Object Creation
 
1 Attachment(s)
Some of you may remember my [URL="http://alice.org/community/showthread.php?t=6831"]Breeding Like Rabbits[/URL] thread.
I've looked into it a bit more, and I've come up with a new way.
Its for real this time!

Basically this allows you to create new objects, [B][I]while the world is running[/I][/B]!
This time around Alice clears up all of the extra objects you created when the world ends. They are also a lot more accessible and can be freely named.

View the example world. I will make this into a usable thing later on, but for now it is a tech demo.
First it will create 500 new spheres on the spot,
then it will continue creating spheres forever and move them away from each other, to show that these objects are usable.

You can move the spheres with the mouse and move the camera with the arrow keys.

[IMG]http://alice.org/community/images/icons/icon4.gif[/IMG] WARNING - Alice has to delete all of these objects when the world stops, so if you create far too many, then Alice might hang for a long time before they are all cleared up.

room14 05-04-2012 03:35 PM

can you delete the objects while running the world?

arty-fishL 05-04-2012 05:33 PM

1 Attachment(s)
[QUOTE=room14;48533]can you delete the objects while running the world?[/QUOTE]Yes you can. You can also create copies of copied objects.

In this attached example 5 spheres will be created on the spot, then more will be cloned from the previous cloned object and old ones deleted 100 times as it moves like a weird caterpillar thing. Finally all clones will be deleted.

Mr Kidnapper 05-04-2012 05:56 PM

Excellent. Now users concerned with world size don't have to deal with it. They can create a scene procedurally.
One question though: Since we can delete these objects afterwards, this means I can control these cloned objects after creating them?
Do I have to create some sort of act method that is initialized upon cloning? The object is then completely left alone until deletion. I can deal with that, since I'm kind of used to working that way.
Do I have to create some kind of gigantic list for specific types of cloned objects? May be somewhat annoying.

What kind of cloning are you doing? From my information, what Alice does is create exact copies of objects and lists them as new, entirely different objects.
For perfect efficiency, the kind of cloning you want to do is referencing (Java equivalent is using constructors), which means it creates objects based off of the old one and any data values either point to the old one or are modified.
This is good for users with low amounts of VRAM since textures take up a lot of room and make a lot of drawcalls.
Good job for solving the cloning memory leak issue though. Impressive.
Oh hey. You also fixed that bug where it would clone + the number of times play has been pressed.

x2495iiii 05-04-2012 09:38 PM

If textures are what you're worried about, I'd stick the original object's texture somewhere global, delete its personal texture, and make it reference the global texture. That way its clones would do the same and you'd ultimately have only one texture for the entire set of clones.

I'm curious to see if it's possible to have cloned objects with their own custom variables, methods, and events which still function with the non-cloned objects and methods of the running world. For example, could we clone an enemy with an event to chase the player and get a mob going after them?

dubastot 05-04-2012 10:31 PM

Amazing work arty, I am amazed at all the great things the forum members come up with.

Mr Kidnapper 05-04-2012 11:38 PM

Well, the mesh is still not referenced from the original, but I suppose that would work.
Unfortunately having new methods and variables for cloned objects isn't possible since that goes against the idea of cloning them while a world is playing. They still have their own separate methods, variables, and events copied from the original though.
I don't see how you couldn't create a kind of mob movement at the world level though. You could add them to a list upon creation and have a world level method act on all of the items in the list.

x2495iiii 05-05-2012 02:05 AM

Lists aren't very well supported across all versions of Alice, however. I've noticed about a 50/50 chance of it not working or flat-out crashing Alice upon opening a world with a list and list methods in it.

The reason I ask is that I've already demonstrated that it's possible to make methods that work with each other in such a way as to allow for vagueness when handling actions (e.g. instead of if target = zombie1, do zombie_die; zombie turn red, event handler for each zombies which trigger if it turns red).
I tested to see if simply copying objects with events designed to work with vague world methods will work, and it does quite beautifully. I'm simply curious if the copying of the object at runtime is similar to the copying in the world-editor, because if it is, zombie mobs with separate but simultaneous actions will be a definite reality.

arty-fishL 05-05-2012 05:32 AM

Im not to sure if I'm going to give you all the answers you need, there's quite a lot of discussion here, but I'll give it a go.

Cloned objects are exact copies of original objects, they exist in the world as if they had been copied before playing it. Because they did not exist before playing, they should not exist when playing ends, so Alice deletes them.

They retain all of the original features of the master object before cloning, all methods, events, variables, properties, functions, textures, sounds, subparts etc.

If the original object, or any of the clones are modified, then the other existing clones will not be changed, but new ones will be in the new form when produced.

You cannot relatively call a method, you must have the object exist before runtime to use its methods; however there are plausible workarounds.

You can have events of objects, so you can have an object watch for a state change of a world level variable. You can set the world level variable unique to whatever object you want to use (which can be retrieved from the new object variable or new objects list).

Each object will then have its event triggered, but you would only want one object to respond. You can do this by having each object check if the world variable refers to that object. On the object you can have a "myself" object variable set to that object. When the object is cloned, the myself variable will change to the new object, so just check if the world level variable is equal to the myself variable and then do whatever you want it to.

Any questions?

zero00 05-06-2012 02:05 PM

When do you think you will be able to release this as an addon for Alice?


All times are GMT -5. The time now is 08:19 AM.

Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.