So, in order to make my Ninja survival game more fun and, ell, more toward its goal it needs a scoreboard.
Best, if not only, tutorial I could find is that one of Goran.
But Blender doesn’t seem to like it, at least not anymore…
Here’s the code from Goran:
from bge import logic
scores = []
def display():
scene = logic.getCurrentScene()
writer = scene.objects ["Naming blah"]
rank = 1
name = logic.globalDict["name"]
score = logic.globalDict["score"]
tup_entry = (rank, name, score)
scores.append(tup_entry)
for entry, i in zip(scores, range(len(scores))):
new_writer = scene.addObject(writer, writer)
new_writer ["Text"] = "{:d} - {:s} - {:.0f}".format(*entry)
new_writer.worldPosition.y -= 1.25 * i
new_writer.localScale = writer.localScale
def setName():
scene = logic.getCurrentScene()
name = scene.objects ["Name blah"]
logic.globalDict["name"] = name["Text"].strip()
def setScore():
cont = logic.getCurrentController()
score = cont.owner
logic.globalDict["score"] = score["Text"]
And the error BGE coughs up:
Blender Game Engine Started
Python script error - object 'Naming blah', controller 'Python':
Traceback (most recent call last):
File "C:\Users\251609\Documents\Tattorack SAA\Ninja game\Test arena\Test arena.blend\ScoreBorad.py", line 18, in display
ValueError: scene.addObject(object, other, time) KX_Scene (first argument): object must be in an inactive layer
Blender Game Engine Finished
So, the Text object “Naming blah”, the text object that should retrieve the name, rank and score, must be on another layer that isn’t used by anything…
Moving the text object there, naturally, stops any errors, but now how does it create the list when its in an inactive layer and not showing itself???
1 - You start the game
There is a HUD text object that is the score, and it updates that constantly to the module with “ScoreBoard.setScore”
2 - You die, an “ENTER NAME” screen pops up as overlay scene. The HUD overlay gets removed but not forgotten.
No python happening here, just typing your name using a single logic brick keyboard sensor and some text properties.
3 - you press enter and the score board scene pops up.
As per Gorans tutorial, the text object, placed in the active layer, is attached to “ScoreBoard.display”
That should retrieve the name just typed in the previous scene, the score of the HUD scene, and the rank (not yet specified).
EDIT: see for yourself: https://dl.dropboxusercontent.com/u/1071079/Test%20arena.rar
(SEFD for movement, has mouselook, for quick death commit suicide by jumpimg off the edge)
Aaand I SWEAR I wrote a reply to Monster, where did it go!?!
Make a duplicate of Writer, and name it Writer_new.
Move Writer_new to an inactive layer.
Change addObject(writer, writer) to addObject(“Writer_new”, writer)
I think that should work.
Also, for future reference: if you could actually isolate the problem in a simple .blend, instead of posting a .RAR of your project, that would go a long way in letting us help you (I don’t even have the software to open RAR files, and I don’t feel like getting it just for this one circumstance).
(I first posted it on youtube, then here because I considered it would be better if more people looked at it.
Also, most computers come along with the ability to unzip .rar’s… though you’re on a Linux so I guess thats a little differant ^^; )
Did the above, it gave an error because “writer_new” wasn’t defined.
I defined it as: writer_new = scene.objects[“Writer_new”] (under where “writer” was defined)
That stopped that error, now I have another one:
Line 9
writer = scene.objects[“Naming blah”] (<- What you called “Writer”)
______________________________^
IndentationError: unindent does not match any outer indentation level
Python module can’t be imported - object ‘score’, controller ‘Python’:
SystemError: NULL results without error in PyObject_Call
This whole error train only started when trying to make the actual list.
Just showing the score like in the vid just before this one worked fine…
I would think that to be true for .zip files, but not for .rar. Well, whatever the case may be, I prefer no compression, or gzip when truly necessary.
Did the above, it gave an error because “writer_new” wasn’t defined.
I defined it as: writer_new = scene.objects[“Writer_new”] (under where “writer” was defined)
The name of the object is “Writer_new” not “writer_new” (capitalization matters). Please do exactly what I instructed, and nothing else.
As for the indentation error … Well, it’s an indentation error - just make sure the indent aligns properly and that should go away.
the tab error can happen when the script is half with tab and half with “tabs as space”.
there a tool in the text editor to format all in (i suggest spaces as PEP8)
Ok, I forgot to add the " symbol, or actually, I didn’t add those because in most instruction the " is used to get you attention to something that should change or implemented, didn’t know it was meant litteraly here.
No errors now, though its making a list till infinity!
I had to force quite the bge because it would stop adding the name I entered with the score and made Blender jam.
The script is not supposed to run on the writer object. If you actually watch the video tutorial carefully, you’ll notice that it’s running on the Scores object.
Having this logic run on the writer will just run the same script over and over for every new instance, and you don’t want to do that.