Class this is on
by rennie moffat · in Torque Game Builder · 08/20/2010 (4:06 pm) · 17 replies
Is there a way I can set a global variable, so when true or false, a class is effected, rather than an object or owner of a behavior? See, I could have each owner, in it's behavior, run a schedule to see if $isTrue is true but I am hoping since I have a lot of these objects that I can simply set $isTrue to effect a class. So if object is Class this, then if $isTrue is true, Class this is on.
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
so, if I have object "block", that is from blockClass and unless $isTrue is true, it is disabled.
I do not see what I would put into my datablock, if anything? Sorry but I just don't get how this would be coded.
08/20/2010 (4:37 pm)
I am not sure how to code that, I know what you mean but...so, if I have object "block", that is from blockClass and unless $isTrue is true, it is disabled.
I do not see what I would put into my datablock, if anything? Sorry but I just don't get how this would be coded.
#3
08/20/2010 (4:56 pm)
I am not sure what you mean by disabled? Do you want to enable or disable a class from loading at runtime? or just modify it's behavior based on your isTrue flag?
#4
You see, I have 100's of objects, with an identical behavior. I can easily set a schedule to check if isTrue is true. However, since I want to really limit computing (this is for an iPhone app) I was thinking, as opposed to 100s of objects checking every 100ms say if isTrue is true, that if, isTrue is true that an entire class is affected. Saving me a lot of computing power.
08/20/2010 (5:22 pm)
well, regardless of what I want to do, I am simply not sure if I can, though you think I can, allow a flag (global variable bool) to effect a class vs an object.You see, I have 100's of objects, with an identical behavior. I can easily set a schedule to check if isTrue is true. However, since I want to really limit computing (this is for an iPhone app) I was thinking, as opposed to 100s of objects checking every 100ms say if isTrue is true, that if, isTrue is true that an entire class is affected. Saving me a lot of computing power.
#5
Is this what you want Rennie?
08/20/2010 (5:36 pm)
function className::functionName(%this)
{
//do stuff on all objects in that class
}Is this what you want Rennie?
#6
Datablocks are meant to contain all information that objects share...in your case, that's where you want your "isTrue" flag.
08/20/2010 (5:42 pm)
Forget about global variables... Just set the flag in the class' datablock, then when your flag changes state, all you need to do is message the objects that use this datablock.Datablocks are meant to contain all information that objects share...in your case, that's where you want your "isTrue" flag.
#7
Ok, so I can just put any variable in the level datablock? So $isTrue = false; for instance. Then if $isTrue is made == to true at any time in the game, that object is flagged? This is good, but it would still require me to add code to a 100 plus objects (via the level.t2d). Not to be lazy but is there an even easier way?
@Patrick, not really. I think Alain is closer.
08/20/2010 (5:50 pm)
@Alain, Ok, so I can just put any variable in the level datablock? So $isTrue = false; for instance. Then if $isTrue is made == to true at any time in the game, that object is flagged? This is good, but it would still require me to add code to a 100 plus objects (via the level.t2d). Not to be lazy but is there an even easier way?
@Patrick, not really. I think Alain is closer.
#8
If($isTrue == true)
{
if(isObject.class = thisClass)
{
do this
}
}
And as a result, every object of that class is affected.
08/20/2010 (5:56 pm)
So something like...If($isTrue == true)
{
if(isObject.class = thisClass)
{
do this
}
}
And as a result, every object of that class is affected.
#9
I forgot in TGB datablocks are called "config datablocks".
If you do a search on those you should find some examples, but it's hard for me to comment more on this, since I don't know how how your App "flows". I don't want to steer you in the wrong direction. :-(
08/20/2010 (6:26 pm)
@RennieI forgot in TGB datablocks are called "config datablocks".
If you do a search on those you should find some examples, but it's hard for me to comment more on this, since I don't know how how your App "flows". I don't want to steer you in the wrong direction. :-(
#10
08/20/2010 (7:28 pm)
ok. in iTGB, there are datablocks, managed and level. Managed for all, level for what is on each level. There is also the level.t2d, which, I guess are not technically datablocks, but are what I was referring to, since they contain information such as class.
#11
I ran tests with my device, my fps with 300 objects disabled (%this.owner.setDisabled(false)) ran at 24fps. Not bad. However, by just adding in a schedule to call itself meaning...
function objectClass::checkUp(%this)
{
%this.schedule(100, checkUp);
}
...my fps ran at 7. With my schedule called every 500ms, 14fps, @ 1000ms, fps = 18. If my schedule runs to high, the global becomes impractical. So, I need to figure out, is there a way to enable an object (setEnabled(true)) via something other than the object checking up on itself via a schedule.
08/20/2010 (8:08 pm)
Ok so here is a good example of tests which show me that I need to figure out a way to enable an object (setEnabled(true)) beyond calling a schedule inside the objects behavior. I ran tests with my device, my fps with 300 objects disabled (%this.owner.setDisabled(false)) ran at 24fps. Not bad. However, by just adding in a schedule to call itself meaning...
function objectClass::checkUp(%this)
{
%this.schedule(100, checkUp);
}
...my fps ran at 7. With my schedule called every 500ms, 14fps, @ 1000ms, fps = 18. If my schedule runs to high, the global becomes impractical. So, I need to figure out, is there a way to enable an object (setEnabled(true)) via something other than the object checking up on itself via a schedule.
#12
The basic problem, as I see it, is that you have way too many objects. If these objects are AI enabled, then you are going to be in a world of pain when the user with an older device tries to run your game. If I was in your shoes, I would create a pool of say 50 objects and try to reuse these objects in waves to simulate 300 objects.
As an example, if your doing a "shoot em up", you would hide an enemy when he gets killed, and bring the same enemy back when a new wave of attackers are needed. This way you won't need to have as many objects, and you will gain FPS and save memory.
If your objects are not AI, then I would like to know what they are?
08/20/2010 (9:52 pm)
You could just create a "Manager" that keeps track of the objects that need to be switched on or off by maintaining a queue. Then, you only have one schedule to do, but This is going to require a little bit of work on your part. The basic problem, as I see it, is that you have way too many objects. If these objects are AI enabled, then you are going to be in a world of pain when the user with an older device tries to run your game. If I was in your shoes, I would create a pool of say 50 objects and try to reuse these objects in waves to simulate 300 objects.
As an example, if your doing a "shoot em up", you would hide an enemy when he gets killed, and bring the same enemy back when a new wave of attackers are needed. This way you won't need to have as many objects, and you will gain FPS and save memory.
If your objects are not AI, then I would like to know what they are?
#13
A wave/pool idea is interesting. It would require a lot of work as I would have to say have 50 tiles, on a scene with 300, then record each position, they are in and need to be in, making sure I do not double up or miss any tiles. So there is no confusion, missed tiles, doubled tiles etc.
One thing I am testing now is a on/off switch. I already use this for my enemies. Simply put, I place triggers around the levels in appropriate places. When trigger $thisOn = true, if $thisOn == true, then %thisThing.setEnabled(true); (Previously it was set to setEnabled(false). This is good as it saves the computer from rendering the image itself plus the movement the AI would perform.
This is a good idea, but if I can save even multiple scheduling as I would in a on/off scenario with each behavior calling to see if thisIs True, it might be a good way to save even more computing power. How would you create a single manager to manage all the relevant objects?
08/20/2010 (10:57 pm)
the objects are user based objects. Each is a tile, I should put that in quotes, as they have nothing to do with a t2dTileMap. They are simply objects placed around each level. They, when pressed (onMouseUp) by the user, call the player to move to their position.A wave/pool idea is interesting. It would require a lot of work as I would have to say have 50 tiles, on a scene with 300, then record each position, they are in and need to be in, making sure I do not double up or miss any tiles. So there is no confusion, missed tiles, doubled tiles etc.
One thing I am testing now is a on/off switch. I already use this for my enemies. Simply put, I place triggers around the levels in appropriate places. When trigger $thisOn = true, if $thisOn == true, then %thisThing.setEnabled(true); (Previously it was set to setEnabled(false). This is good as it saves the computer from rendering the image itself plus the movement the AI would perform.
This is a good idea, but if I can save even multiple scheduling as I would in a on/off scenario with each behavior calling to see if thisIs True, it might be a good way to save even more computing power. How would you create a single manager to manage all the relevant objects?
#14
Rennie... hang on here a second...
You've got 300 'tiles' onscreen... each of which is effectively a button? And these buttons make the user GO to the button's position?
I have a sneaking suspicion that you're going about the game in the wrong way... maybe drop a screenshot and a description of the game in here, and we'll help you optimize your approach a bit?
08/20/2010 (11:26 pm)
[somewhat off-topic]Rennie... hang on here a second...
You've got 300 'tiles' onscreen... each of which is effectively a button? And these buttons make the user GO to the button's position?
I have a sneaking suspicion that you're going about the game in the wrong way... maybe drop a screenshot and a description of the game in here, and we'll help you optimize your approach a bit?
#15
08/20/2010 (11:47 pm)
no you have misread Tim. I could have 300 even 500 objects, but not on screen. They are spread out through a "choose your own adventure" type level. You may come across them, you may not.
#16
08/20/2010 (11:55 pm)
So you're doing point-and-click... but you've got 3 to 5 hundred buttons in a given level? And these aren't all onscreen... What's the navigation look like? (i.e., if they aren't all onscreen, how do you GET them onscreen? is it scrolling?)
#17
08/20/2010 (11:57 pm)
simple camera mount to player.
Torque Owner Alain Labrie
Ware-Wolf Games