Property Timer , sprite according to mouse location and more questions. :)

Hello everyone. I need some help on these stuff. I’m still learning programming so please bear with me.

All about scripting:

  1. How can we use the Timer property? Like activate a node whenever it hits a certain time, etc etc.

  2. I’m building a prototype for a game. I need the sprite to change or face a certain direction where the mouse is located. Just limited to left and right. Just like the game Nuclear Thrones. Screenshot below.

  1. I’m wondering what’s the use of Loops in game programming? I don’t use it that much. Any game related examples please. :slight_smile:

  2. The damage shows up whenever you shoot an enemy. Like it’s your DMG minues the enemie’s DEF. (Screenshot below)

THANK YOU SO VERY MUCH GUYS! THIS FORUM ROCKS!!

  • Chris
  1. It is a property. You can use a property sensor to evaluate the content.

  2. Loops are necessary when you process several elements the same way. This is a basic processing not limited to games.

Example?

  • inventory

the inventory can be a collection for slots. You loop over all slots processing them slot by slot.

other example: checking sensor status:


import BGE

def actLikeAND():
    if allSensorsPositive():
        activateAllActuators()
    else:
        deactivateAllActuators()

def allSensorsPositive():
    for sensor in bge.logic.getCurrentController().sensors:
        if not sensor.positive:
            return False
    return True

def activateAllActuators():
    controller = bge.logic.getCurrentController()
    for actuator in controller.actuators:
        controller.activate(actuator)

def deactivateAllActuators():
    controller = bge.logic.getCurrentController()
    for actuator in controller.actuators:
        controller.deactivate(actuator)


more?
Searching for objects:


import bge

def findByPropertyName(propertyName):
    return [object for object in bge.logic.getCurrentScene().objects
            if propertyName in object]


def findByPropertyValue(propertyName, value):
    return [object for object in bge.logic.getCurrentScene().objects
            if propertyName in object and object[propertyName] == value]


  1. this behavior of a display. Typically whenever the status of something changes, you notify any interested listener. The listener reads the new status and shows it. There can be none, one or more listeners.

An option is to send a message.

A character gets damage, the damage dealer stores this damage in a property at the character and sends a message “damage received”.
A damage viewer text object associated with the character wakes up on message. It reads the damage from the property and shows it on screen for a while). Viewers listening for other messages (e.g. “health change”) will do nothing.

Optional: If the status change can be expressed as string, you can send the new status as message body.

I hope it gives some ideas.