Game Development Community

Resolved- Help I am going bananas. Scripting problem.

by Christian Rademan · in Torque Game Builder · 10/18/2007 (1:31 am) · 5 replies

I am making a pacman clone. And I need to spawn a fruit every x seconds or so.
Now the problem is that I maybe want more than one fruit at a time.
Should I create a fruit object in script every time I need a fruit?
Or should I set up one in the level editor and clone it?
How do you clone an object ? I can't seem to access any methods in its class.
help please. The frustration of this is getting me down.
Thanks.

#1
10/18/2007 (3:09 am)
Ok i got it working. If you clone an object be sure to do it like this.
%new = %thething.clone(TRUE);
Otherwise you will have a problem.
Now I have a message from the console that gives me this error:

con::execute - 0 has no namespace :on sceneRemove

It happens each time I clone an object.

this is the script I use:

$pFruit=pFruit.clone(true);
$pFruitBubble=FruitBubble.clone(true);
$pFruitBubble.mount($pfruit);

It does'nt seem to stop anything working.
#2
10/18/2007 (12:44 pm)
What is pFruit and FruitBubble? It seems like you should be able to just clone one object (the fruit) and place it with "setPosition".

Ok my guess is the "fruit bubble" is part of the gui showing the fruit you have already collected? And you are using a sceneobject which follows the camera rather than an actual gui control, so that may make sense.

That message means to me that something is getting removed from the scene and it doesn't have a valid class, for whatever reason, so it can't find the appropriate onsceneremove callback. I don't see why cloneing or mounting would cause anything to get removed from the scene, perhaps that is happening somewhere else in your code?

If you have a lot of different types of fruit it can be annoying having to create a template for each one, of course you can always clone it and then manually set the image map after.
#3
10/18/2007 (11:28 pm)
PFruit is my template object for my fruit.
I use a scene object to clone the fruit and place it in the scene.
The fruitbubble is just a little bubble that is mounted to the fruit to make it look pretty.
#4
10/19/2007 (1:33 pm)
Hi

Assuming there are no other variables in your fruit creationg problem, I would create a function that is ran to create all the fruits you want in the positions you want and then schedule itself to create another fruit if there's none at that place. One way to control this is the fruit, before being deleted, informing some script object or global that the position is now available.

I personally never use clones. I always use script objects that control all "production" needs. :) Hope it helps.
#5
10/20/2007 (7:44 am)
Or you may use a simset to control spawning positions. When a fruit is deleted you can tell the engine that there is a position available. You can see how this works in the mole tutorial. It is great!