Please forgive my ignorance I just started scripting in Python a few days ago. I am fluent in visual basic but terrible at C++, etc. and I’m finding Python difficult to grasp.
Here’s what I’m doing:
I am making a simple bowling game. It’s my first ever attempt at using the game engine and Python. It’s great experience.
I am storing player scores in a “list” in a global variable (property)
Player1_Frames = [-1,-1]*12
Player2_Frames = [-1,-1]*12
Scores = Scoresheets()
GameLogic.Scores = Scores
As you see, it stores 24 integers, populated with “-1” until the player bowls a frame, then it’s simply updated with the number of pins the player hits with each ball.
What I want to do is display a scoresheet when the player(s) press a key. I am doing this by using a text plane with a string property called “Text” like this
I want to populate this string with the scores. Obviously I have to coerce integers into string bits and can do so using the “str()” function.
Problem is, I’ve tried multiple ways of writing this and all yield the same result. If I have more than one value I get an error.
Example script as follows:
cont = GameLogic.getCurrentController()
owner = cont.owner
Scores = GameLogic.Scores
Player1_Frames = Scores.Player1_Frames
UpdPl1 = cont.actuators[“UpdPl1Score”]
ScoreEmpty = True
Pl1ScoreStr = ‘’
for item in Player1_Frames:
if item <> -1:
if item <= 9:
Pl1ScoreStr += ’ ’ + str(item)
Pl1ScoreStr += str(item)
ScoreEmpty = False
Pl1ScoreStr += ’ ’
Pl1ScoreStr += ’ ’
if not ScoreEmpty:
UpdPl1.value = str(Pl1ScoreStr)
So, say player rolls first ball, picks up 9 pins
Score reads: 9
player picks up the last pin with second ball
Score should read: 9 1
Instead it read: [ + [9 + [extra characters after expression]]]
I’ve been reading a lot on the Python site and searching the forums and tutorials, I’m just not getting it. Help? Someone?
P.S. Sorry the script examples are difficult to read, the forum removes all spaces and tabs :^(