Computer Science Canada OOT, destorying objects |
Author: | Scott [ Fri Feb 13, 2009 8:00 pm ] | ||||
Post subject: | OOT, destorying objects | ||||
Hi I can do this to make an object
my question is can I then remove that object? example
if yes, can you please give me the correct syntax to do so? Thank you ![]() |
Author: | Scott [ Fri Feb 13, 2009 11:13 pm ] | ||
Post subject: | Re: OOT, destorying objects | ||
I didnt figure out my first post but I have another question so hopefully you can also help me with this. Well Im making an rpg and I have a shop, and a restock procedure. In that procedure it is supposed to make objects but I dont know how to get the computer to designate the object name. Ive also relized just now that I dont know how to get a program to make and create a variable. Here is part of the code
Hopefully someone can help me. Thanks to anyone who helps even a bit ![]() |
Author: | michaelp [ Mon Feb 16, 2009 3:40 pm ] |
Post subject: | Re: OOT, destorying objects |
For the first post: I think if you put that in a flexible array of 1, you would be able to get rid of it by setting the size to 0. See here and here. Hope that helps. ![]() |
Author: | CodeMonkey2000 [ Mon Feb 16, 2009 4:41 pm ] | ||
Post subject: | Re: OOT, destorying objects | ||
For the first question try
And for the second question, I'm not sure what you want. You should look through the Turing Walkthrough for tutorials on pointers and classes. |
Author: | DemonWasp [ Mon Feb 16, 2009 6:38 pm ] |
Post subject: | RE:OOT, destorying objects |
For the second question, you probably want arrays. They let you have multiple objects with a single name. |
Author: | Scott [ Mon Feb 16, 2009 7:37 pm ] |
Post subject: | Re: OOT, destorying objects |
Thanks so much DemonWasp I never even thought of applying arrays to that. I haven't tried the answers to the first question but I'm sure they will help thanks everyone. |
Author: | A.J [ Mon Feb 16, 2009 7:42 pm ] | ||||||
Post subject: | Re: OOT, destorying objects | ||||||
CodeMonkey2000 wrote: For the first question try
And for the second question, I'm not sure what you want. You should look through the <a href="http://www.compsci.ca/v3/viewtopic.php?t=8808">Turing Walkthrough</a> for tutorials on pointers and classes. instead of :
you can also do :
omitting the 'Helmet' also works too |
Author: | copthesaint [ Tue Feb 17, 2009 8:39 am ] | ||
Post subject: | Re: OOT, destorying objects | ||
Why don't you just use a bind statement?
The only problem is you need an external variable to bind too. |
Author: | DemonWasp [ Tue Feb 17, 2009 9:13 am ] |
Post subject: | RE:OOT, destorying objects |
I'm assuming his problem was "I want to make some variable number of objects and have some way of referring to them", in which case bind doesn't do what he wants (bind is similar to how parameter-passing to procedures/functions works in Turing). The way to do this is with arrays or flexible arrays (or a proper collection object...). This is how you solve the "inventory" problem; it makes the code a LOT simpler and easier to manage, and it certainly makes it easier to generalise to more kinds of objects. |
Author: | Scott [ Tue Feb 17, 2009 5:41 pm ] |
Post subject: | Re: OOT, destorying objects |
Demon Wasp is close to correcct, I want the game to create objects (instances) while its running. What im trying to do is make a shop in my text based RPG, That when you buy from the shop it needs to generate instance(object) and put it in the player inventory. |
Author: | DemonWasp [ Tue Feb 17, 2009 6:26 pm ] | ||
Post subject: | RE:OOT, destorying objects | ||
Example of exactly how to do this: Let's assume that you have a base class "Item" from which all in-game items descend. Item probably has information about, for example, the item's weight and price, name and description and so forth. It WILL NOT have such things as weapon damage or armour benefits (for those, you would have a "Weapon" class and an "Armour" class, both of which would inherit from Item). Your ShopKeeper class then looks like the following:
I haven't tested the above code, it's just an overview. |
Author: | Scott [ Tue Feb 17, 2009 8:00 pm ] |
Post subject: | Re: OOT, destorying objects |
:O Thank you soo much Demon Wasp. Yes I have it set up with Item as the top class but I never thought of it as a large array from which to make items from like that. That helps so much and now I can move on with my RPG ![]() Also on a side note its not game progress stopping but if anyone knows the for sure answer that "free Helmet1" works please say. |
Author: | DemonWasp [ Tue Feb 17, 2009 9:30 pm ] | ||||
Post subject: | RE:OOT, destorying objects | ||||
AJ's right. You can new and free objects either with the class name spelled out for you:
or you can new/free without the class name:
The reason that one might use the first form is if you have a bunch of variables (for example, Item 's) but want to have them actually be Sword / Shield / etc. |
Author: | Scott [ Tue Feb 17, 2009 10:24 pm ] |
Post subject: | Re: OOT, destorying objects |
Thanks everyone, especially DemonWasp. All my questions have been answered and so the topic has been marked accordingly. Bye all you extremely helpful people. |
Author: | DemonWasp [ Tue Feb 17, 2009 10:32 pm ] |
Post subject: | RE:OOT, destorying objects |
Don't say bye! Compsci.ca is a community of programmers from complete newb to expert. Come visit frequently, and if you have advice, feel free to contribute. |
Author: | Scott [ Tue Feb 17, 2009 10:39 pm ] |
Post subject: | Re: OOT, destorying objects |
No worries haha, I don't mean bye for good, I mean goodbye to this topic. I plan on staying here for a very long time. |
Author: | A.J [ Tue Feb 17, 2009 10:55 pm ] |
Post subject: | Re: OOT, destorying objects |
that's good to hear ![]() |