Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Deleting objects boggling me
Old
jesusblake
Guest
 
Status:
Posts: n/a
Default Deleting objects boggling me - 09-22-2007, 01:25 AM

Hi. New to Alice and the site so please forgive my pedestrian question. It's driving me batty.

I'm doing a city skyline with various planes, helicopters, ostriches flying over it. Completely simple, beginner stuff. Problem is, I can't figure out how to delete the objects when I'm done with them. So they just sit offstage (outside of lens angle) somewhere. Sometimes I use them again and when I do, I want them to come in at different points then where they are 'waiting'. So then I have to figure out were they ended up, 'fly' them around the lens angle, line them up and have them come onstage at a different place.

Is there a way to 'delete' an object after use? I'm sure this q has been asked and answered but I couldn't find it with searching.

Thanks in advance,
Blake
   
Reply With Quote
Old
Ping
Guest
 
Status:
Posts: n/a
Default 09-22-2007, 01:33 AM

Make the Object either 0% opaque, or SetVisibile False, both can be found in the Objects properties section, and if u want them to fly back in at different spots, you can set up hidden objects around the air using the same method i just told you, and you can have the planes and helicopters MoveTo those objects once your done with them in preparation for the next time you need them. I hope this answers your question.
   
Reply With Quote
Thanks
Old
jesusblake
Guest
 
Status:
Posts: n/a
Default Thanks - 09-22-2007, 01:49 AM

Ping: Thanks for the tips. I suppose those objects have to always exist somewhere after calling them.
B
   
Reply With Quote
Old
Ping
Guest
 
Status:
Posts: n/a
Default 09-22-2007, 01:52 AM

yup, unfortunately, another bad thing is that you cant create objects after the program is executed, which is kind of lame imo.
   
Reply With Quote
Create after execute?
Old
jesusblake
Guest
 
Status:
Posts: n/a
Default Create after execute? - 09-22-2007, 01:56 AM

Don't understand what you mean...You mean can't create new objects in the middle of execution? I'm totally new but don't understand why you would need to.

B
   
Reply With Quote
Old
Ping
Guest
 
Status:
Posts: n/a
Default 09-22-2007, 10:16 AM

you really dont need to, but it would be nicer if you could destroy and recreate the objects at a location, for example in a first person shooter if i wanted to kill stuff and then make new ones run at me, instead i have to make the old ones invis then move back to the spot i want them to come from. just a lot of hassle
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 09-22-2007, 10:53 PM

I think that what Ping is really saying is that you cannot write code to create new objects at runtime in Alice. That is one of the limitations of Alice. Rather, you must manually create all of the objects that your program will need by either dragging them from the gallery into the world or clicking on them in the gallery and selecting the button to add them to the world. You must do that when you are writing the program. Objects that won't be needed in the scene until later can be made invisible until they are needed, at which time they can be made visible.

As you progress in your programming career, you will learn that true object-oriented programming languages such as Java, C#, and C++ allow you to write code to create new objects when you need them, and to write code to cause objects to be effectively deleted when you no longer need them. (The mechanism for doing the latter differs significantly between Java, C#, and C++)

So, why would you need to be able to create new objects at runtime? Assume that you are writing a simulation of a battle scene where your forces consist of a large number of soldier objects, and the strength of your forces depends on the results of previous events in the battle. The number of soldiers on your side may be small or or may be large. You would like to be able to write code to create your soldiers at a point in the animation where your forces are massing for an offensive. You can't possibly know how many soldiers will be required at that point in the battle when you are writing the program, so it is fairly impractical to create them all manually when you are writing the program.

Why would you want to delete them at runtime? I believe you have identified a few good reasons. In addition to the reasons you have listed, every object occupies memory and it can be useful to free up the memory occupied by an object when that object is no longer needed. Then that memory can be used to create another object of the same or a different type later.

From the nature of your questions, it seems that you may be able to make good use of the free online tutorials at http://www.dickbaldwin.com/tocalice.htm
   
Reply With Quote
One more point on creation of objects at runtime
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default One more point on creation of objects at runtime - 09-23-2007, 08:58 AM

One other point regarding the creation of objects at runtime. Going back to the battle scene, assume that your forces consist of 500 soldier objects, (ignoring the fact that Alice 2.0 would probably become unusable if you added 500 objects to the world). With Alice 2.0, you would have to either drag 500 objects from the gallery or drag a single object from the gallery and make 499 copies of that object using the object manipulator buttons while you are writing the program. Either way, the manual effort would be significant.

Even more significant would be the manual effort required to set the visibility property on each of the objects if you really wanted them to be invisible when the program starts running.

With Alice 3.0, we will (presumably) have the ability to create objects at runtime. That means that we will be able to write a few lines of code in a loop at any point in the program to cause all 500 soldier objects to be created. We will be able to cause that code to store references to those 500 objects in an array or a list, and to be visible or invisible as the needs may dictate. We will be able to manipulate them either individually or as a group using the references in the list.

Similarly, we will be able to effectively delete all 500 objects with a few lines of code in a loop, making them eligible for garbage collection. This will free the memory occupied by that set of 500 soldier objects so that the same memory can then be used for the creation of 1000 tanks. None of that is possible with Alice 2.0.

If you like programming, I predict that you will fall in love with Alice 3.0 and true object-oriented programming once it becomes available and you learn how to use it.

Last edited by DickBaldwin; 09-23-2007 at 08:59 AM. Reason: Clarification
   
Reply With Quote
Reply

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 ©2023, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.