Goran's scoreboard script outdated... workaround?

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???

Because it creates a copy of that object dynamically (see addObject).

It does not retrieve “name, rank and score” it is a view object. It shows this data (the reason why this function is called “display” ;)).

I see no outdated code.

Tell us what’s happening in-game because just saying, “this doesn’t work”, isn’t very helpful.

edit: I guess Monster got it haha

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!?!

This can be changed for style

for entry, i in zip(scores, range(len(scores))):
for i, entry in enumerate(scores):

What confuses me is, that I thought the restriction that “master” objects has to be in an inactive layer where for the AddObject-Actuator only.

So I would not expect the above error if the “writer” is in an active layer.

Edit: I just tested with 2.68. The original needs to be in an inactive layer.

Could it be the “writer” is the original you make a copy from [ the one that triggers ScoreBorad.display() ]?

Edit: I missed the link somehow … but I can’t download right now anyway.

Try this:

  • 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).

It was …

(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…

Here is a normal .blend file: https://dl.dropboxusercontent.com/u/1071079/Test%20arena.blend

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)

I already founnd that error.
Christ, its worse than an english university teacher! XD

Now its saying “Key not in list” >_< :
Line 9 in display
KeyError: “Clist[key]: ’ ‘Writer_new’ ’ key not in list”

The current code looks like:

from bge import logic

scores = []

def display():
    
    scene = logic.getCurrentScene()
    writer = scene.objects["Naming blah"]
    Writer_new = scene.objects["Writer_new"]
    
    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_new, writer)
        new_writer ["Text"] = "{:d} - {:s} - {:.0f}".format(*entry)
        
        new_writer.worldPosition.y -= 0.50 * 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"]

You didn’t follow instructions.

As I said before, it should be addObject(“Writer_new”, writer). It’s supposed to be a string, not an object.

You’re not supposed to even have the scene.objects[“Writer_new”] line - you’re doing something completely different from what you’re being told.

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.

EDIT: scratch that, solved it already ^^;

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.

Yeah I got that part, thats how I solved the repeat.
Thanks for the help… must’ve been tedius…