Hello people, and thanks in advance for whatever help you can give me (if any at all)
Here is my problem:
I am trying to create a message system for my game (because i was told it was one the easiest things to program when you are starting out), but sadly, it isn’t exactly doing… anything. X_X I’ve tried, and i’ve tried, and i’ve re-written just about everything half a dozen times, but it still does absolutely nothing (well, at least as far as i can see, and that’s kind of the main point of it, so to speak…)
The whole working of the code is to get the object the player is talking to, then get certain properties from it, then send them to the 4 text lines in a ‘typing’ fashion, which the player can read. but it isn’t sending anything.
it also does something simalar for the answers/questions part of it, but once again, i have no idea what i did wrong (though i am sure that it’s quite a bit):
#------------------------
# Name: Message_system
# Purpose: This script is the message system, just as the title says. What
# it does is get the text from an Npc and sends it to the in-game
# dialogue box so that the player can read it.
#
# Author: Alan M. Burnett
#
# Created: 08/13/2011
# Copyright: (c) Alan M. Burnett 2011
#------------------------
import bge
player = bge.logic.getCurrentController()
touch = player.sensors["Touch"]
person = touch.hitObject
commentnum = person.commentnum
mor = False
while mor == False:
if hasattr(person, 'text' + commentnum):
mor = True
else:
commentnum -= 1
text = person.sensors['text' + commentnum]
time = person.time
count = 0.5
words = text.split(' ')
#------------------------
# When called, this section updates the text on the line, waiting a short time
# in order to create a 'typewriter effect'.
#------------------------
def text_update(word, time_new, dialogue_set):
nchar = word.split() # splits the word into seperate characters
wait = 0
for n in nchar: # does the next program for each character in word
dialogue_set.Text = dialogue_set.Text + n # updates the text
time_new = time_new + 1 # updates how long the the updater should wait
while time < count * time_new: # tells updater to wait
wait = 1
time_new = time_new + 1 # updates how long the the updater should wait
while time < count * time_new: # tells updater to wait
wait = 1
dialogue_set.Text = dialogue_set.Text + ' ' # adds a space after the word
#------------------------
# When called, this code makes the game wait until the player press the f key
#------------------------
def action_button():
next = 0
while next == 0: # makes the scene wait until next is nolonger equal to 0
if Blender.Draw.FKEY: # checks if the f Key is being pressed
next = 1 # sets next to 1 if the f Key is pressed
#------------------------
# This section of coding gets the dialogue, seporates the words, counts the letters,
# and sees how many words can fit on each line in the message box.
#------------------------
def message_text(words, count): # get the dialogue (word) and the text count (count)
dialogue1 = Blender.Object.Get('TEXT001') # gets the first text object
dialogue2 = Blender.Object.Get('TEXT002') # gets the second text object
dialogue3 = Blender.Object.Get('TEXT003') # gets the third text object
dialogue4 = Blender.Object.Get('TEXT004') # gets the forth text object
dia1 = dialogue1.Text
dia2 = dialogue2.Text
dia3 = dialogue3.Text
dia4 = dialogue4.Text
dia1 = ''
dia2 = ''
dia3 = ''
dia4 = ''
time_new = 0 # set's the dialogue typewriter dialogue time
dialogue = 0 # set's the dialogue typewriter dialogue time
type_character = 1
page = 1
for word in words: # runs this coding for each item in words using word as the items place
dialogue = dialogue + len(word) # counts the leters in word, then adds it to dialogue
if dialogue >= 240 * page: # if the page is full, program will
# wait for the user to push a button before moving on to the
# next page.
action_button()
dialogue1.Text = '' # clears line 1 of all text
dialogue2.Text = '' # clears line 2 of all text
dialogue3.Text = '' # clears line 3 of all text
dialogue4.Text = '' # clears line 4 of all text
page = page + 1 # adds 1 to page
text_update(word, time_new, dialogue1) # runs the update program
elif dialogue <= 60 * page: # sees if the text will fit on the first line
text_update(word, time_new, dialogue1) # runs the update program
elif dialogue <= 120 * page: # sees if the text will fit on the second line
text_update(word, time_new, dialogue2) # runs the update program
elif dialogue <= 180 * page: # sees if the text will fit on the third line
text_update(word, time_new, dialogue3) # runs the update program
else: # sets the text to the final line
text_update(word, time_new, dialogue4) # runs the update program
action_button()
textnext()
#------------------------
# When called, this script checks if there is a textnX
# if there is, it sets the commentnum to that value so that the object will say
# that text the next time the player talks to that object
#------------------------
def textnext(): # this is the program title.
if hasattr(person, 'textn' + commentnum): # checks if there is a textn prop for this text
con = person.sensors['textn' + commentnum] # sets con to the textn volue
person.commentnum = con # sets commentnum to the textn volue
#------------------------
# When called, this script prints the answers message so that the player can
# read them, then handles what happens when the player chooses one
#------------------------
def answer_stuff(letter): # this is the program title.
mark = 'answer' + letter + commentnum
con = person.mark # gets the text for the choice
message_text(con, count) # prints the text for number1
if hasattr(person, 'answer' + letter + 'c' + commentnum): # checks if there is an answer prop
con = person.sensors['answerbc' + commentnum] # gets the answers
person.commentnum = con
#------------------------
# When called, this script checks to see if there is an auto proporty on the
# speaking object, and if there is, it returns a value of true
#------------------------
def auto(): # this is the program title.
if hasattr(person, 'auto' + commentnum): # checks if there is an answer prop
return True
#------------------------
# When called, this script displays a set of choices for the player to choice
# between.
#------------------------
def answerprog(): # this is the program title.
if hasattr(person, 'answer' + commentnum): # checks if there is an answer prop
answer = person.sensors['answerc' + commentnum] # gets the answers
choices = answer.split(' /ct ') # splits the answers into differnet parts
answer_count = 1 # indicates that there is at least 1 answer
choic = 0 # sets choice to 0 so that the player can choose a choice themself
answerbg1 = Blender.Object.Get('answerbg001') # gets choice text 1 ready
answerbg2 = Blender.Object.Get('answerbg002') # gets choice text 2 ready
answerbg3 = Blender.Object.Get('answerbg003') # gets choice text 3 ready
answerbg4 = Blender.Object.Get('answerbg004') # gets choice text 4 ready
for answr in choices: # runs this section once for each answer
ansbg = Blender.Object.Get('answerbg00' + answer_count) # makes answerbg00X appear
dialogue1 = Blender.Object.Get('CHOISE00' + answer_count) # gets the choice box
dialogue1.Text = answr # hands the choice box the choice, showing the choice text
ansbg.appear = 1 # tells the answers background to appear
answer_count = answer_count + 1 # adds 1 to answer_count
while choic == 0: # tells the program to run this section ontil choic is not equal to 0
if answerbg1.clicked == 1: # checks if answer 1 has been clicked
choic = 1 # sets choic to answer 1
elif answerbg2.clicked == 1: # checks if answer 2 has been clicked
choic = 2 # sets choic to answer 2
elif answerbg3.clicked == 1: # checks if answer 3 has been clicked
choic = 3 # sets choic to answer 3
elif answerbg4.clicked == 1: # checks if answer 4 has been clicked
choic = 4 # sets choic to answer 4
answerbg1.appear = 0 # makes answerbg00X disappear
answerbg2.appear = 0 # makes answerbg00X disappear
answerbg3.appear = 0 # makes answerbg00X disappear
answerbg4.appear = 0 # makes answerbg00X disappear
if choic == 1: # runs this if choice is equal to 1
answer_stuff('a') # runs answer_stuff for answer a
elif choic == 2: # runs this if choice is equal to 2
answer_stuff('b') # runs answer_stuff for answer b
elif choic == 3: # runs this if choice is equal to 3
answer_stuff('c') # runs answer_stuff for answer c
else: # asumes that teh choice is 4 (since it wasn't 1-3) and runs this section of code
answer_stuff('d') # runs answer_stuff for answer d
#------------------------
# When called, this script displays a set of choices for the player to choice
# between.
#------------------------
message_text(words, count)
answerprog()
while auto() == True:
message_text(words, count)
answerprog()