Game Object: sendMessage

sendMessage(subject)
  • Sends a message header.  No body.  Sent to all game objects.

subject:

  • Message header
  • Type: string
sendMessage(subject, body)
  • Sends a message header and message body to all game objects.

subject:

  • message header
  • Type:  string 
body:       
  • message body
  • Type:  string
sendMessage(subject, body, to)
  • Sends a message header and a message body.  Sent to a game object.

subject:

  • message header
  • Type:   string 
body:       
  • message body
  • Type:   string
to: 
  • The name of the game object to send the message to
  • Type:  string
Sample Code

################### send a message header to all game objects
    
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# subject header
subject = "Health Potion"

# send message
obj.sendMessage(subject)

Sample Code

################### send a message header and body to all game objects
    
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# subject header
subject = "Health Potion"

# subject body
body = "10"

# send message
obj.sendMessage(subject, body)

Sample Code

################### send a message header and body to one game object
    
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# subject header
subject = "Health Potion"

# subject body
body = "10"

# game object to send message to
# my game object is named Suzanne

to = "Suzanne"

# send message
obj.sendMessage(subject, body, to)