Alice Community  

Go Back   Alice Community > General Discussion > The Lounge

Reply
 
Thread Tools Display Modes
Runtime Object Creation
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Talking Runtime Object Creation - 05-04-2012, 09:21 AM

Some of you may remember my Breeding Like Rabbits 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, while the world is running!
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.

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.
Attached Files
File Type: a2w object creation.a2w (403.9 KB, 47 views)


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [¬º-°]¬

Last edited by arty-fishL; 05-04-2012 at 09:26 AM.
   
Reply With Quote
Old
room14
Senior Member
 
room14's Avatar
 
Status: Offline
Posts: 549
Join Date: Nov 2009
Location: Auckland New Zealand
Default 05-04-2012, 03:35 PM

can you delete the objects while running the world?


:D
   
Reply With Quote
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Default 05-04-2012, 05:33 PM

Quote:
Originally Posted by room14 View Post
can you delete the objects while running the world?
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.
Attached Files
File Type: a2w object super creation and deletion.a2w (409.9 KB, 26 views)


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [¬º-°]¬
   
Reply With Quote
Old
Mr Kidnapper
Senior Member
 
Status: Offline
Posts: 442
Join Date: Feb 2011
Default 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.

Last edited by Mr Kidnapper; 05-04-2012 at 06:04 PM.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 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?


(')>
   
Reply With Quote
Old
dubastot
Senior Member
 
dubastot's Avatar
 
Status: Offline
Posts: 661
Join Date: Apr 2009
Location: Two Steps From Hell
Default 05-04-2012, 10:31 PM

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


I'm a web developer/ designer now.

Last edited by x2495iiii; 05-05-2012 at 01:58 AM.
   
Reply With Quote
Old
Mr Kidnapper
Senior Member
 
Status: Offline
Posts: 442
Join Date: Feb 2011
Default 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.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 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.


(')>
   
Reply With Quote
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Default 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?


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [¬º-°]¬
   
Reply With Quote
Old
zero00
Senior Member
 
zero00's Avatar
 
Status: Offline
Posts: 300
Join Date: Oct 2009
Default 05-06-2012, 02:05 PM

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


==============Some of my Games and Ideas===========

Sky Warrior: http://www.alice.org/community/showthread.php?t=6291
Health Bars: http://www.alice.org/community/showthread.php?p=36968#post36968
Sky Warrior: Dual Force: http://www.alice.org/community/showthread.php?t=7174

Want to make your own space game? http://www.alice.org/community/showthread.php?t=6389
   
Reply With Quote
Reply

Tags
clone, copy, creation, object, runtime

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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