Two Python SimCity Questions

Hello my friends!

I have two Python related question for you all.

  1. My project has a building-creation aspect similar to Sim City. One creates a building by selecting a plot to build on, then clicking the desired building type in a list. The list works by sending a message with the desired building type. Each “plot” has a large number of message sensors, one for each building type. /// My question is, is there a way I could whittle this down to one message sensor, and have the Python script watch the message subjects? There is already a script to control the actuator which watches to see which message is received by which sensor is firing. It could be far more efficient if the script itself could simply watch all message activity and respond appropriately.

  2. As I said, in the game the user can make buildings. The buildings are created by an Add Object actuator. Now, I also want people to be able to demolish buildings. What would be the best way to go about demolishing only one instance of a building? (i.e, if there are two hotels, I can demolish only one hotel and leave the other). Each building instance is contained in a selectable “plot”, which could potentially be useful. As these objects are created in-game, this sort of operation is unusually complicated.

For the record, the game is not a clone or a remake of SimCity. It is something entirely different which contains aspects similar to SimCity. You’ll see soon enough.

  1. you might use a global variable rather than a message (GameLogic.variablename) and have the selected plot read from that (you could have numbers correspond with building types, or just use strings)

2)if, say, ctrl-RMB were the demolish command, I’d have every building check for mouse over plus the hotkey combo (this is assuming you use mouse control). this means that when the hotkeys are pressd, only the building under the mouse is affected.

Could you show some screens or tell more about your game? As a SimCity fan I’d be interested to see what you’re making. I’m making a game with city theme myself.

Heh, message sensors.

  • As Captain Oblivion already stated the solution is to have a global source pool (be it a simple variable or even a full on data structure).
  • You want to get the access to the selected instance directly. Which means you use the ray thats shooting by default from the mouse over sensor and do a “mouseover.getHitObject()”. Then if you have a boolean on that object that controls the activation of an end object actuator; just trigger it from the main python script and it should be gone. ~ What oblivion suggested will work too.Try to think more in python, and less in bricks.

I’m activating the script using the message sensors, though. If I was to use the global variables, wouldn’t I have to activate the script using an Always sensor or something along those lines?

I may have to rethink the way that buildings are controlled. At the moment the buildings are contained within a large bounding box which controls the “plot.” I think I may have to switch to a plane instead…

PSK131: I’m setting up all the logic first, so right now there really isn’t anything to look at. However, I’ll post a thread as soon as there is, and I plan to share some of my scripts shortly. However, as I stated, it’s not exactly Sim City.

When you think about it, it doesn’t really matter too much.

All sensors send a pulse once per frame. They only activate their controller when they get a signal (positive pulse), but they still run every frame. So in theory, if you connect the Always to a Python (which has an if around the control text, so it doesn’t run al the time), there won’t be much difference.

Of course, I may be wrong.

Thanks Toomai…I didn’t know that. I’ll have to experiment and see what happens.

In the meantime, I think the demolishing question may be nullified, as I think I may go with my original plan, which was that only one instance of each building would be allowed at any given time.

Yea, but you would only have one very efficient script instead of some tangled up brick mess.

…It feels like you did a lot of unnecessary things - but it’s really hard to say.

Sorry, I know I’m making even less sense. Just do it your way for now, and then when you release we can all look and have a better grasp of the actual situation.

All sensors are checked every frame. They send a pulse to a controller (activating it) only when they are triggered.

An always sensor (which by default has it’s true level trigger pulsing on) will run the controller always (hence the name) - so even if you have “if” statements, the fact that it’s “always” running means that the python core has to actually check the if statements…

So yea, I would say that by default an always sensor will take up more cycles than a sensor waiting to be triggered.

Although even then, it all really depends on your logic setup…it’s hard to be absolutely certain about these things. However, if you use the “rule of thumb” which states “Use only what you need, disable/remove everything you don’t”, you should be just fine performance wise - in almost any situation.