Jump to content

getForname() issues - returning wrong character name.


Torrent

Recommended Posts

Hey everyone.

 

I'm just messing around with modding PZ and getting to grips with everything. I made a small script that retrieves the player's name and prints it to the console. Annoyingly, it always prints out "Bob" instead of my character's name. Does anyone know why? My code is as follows:

 

 

function TestMod.keyPress(_keyPressed)
if _keyPressed == 25 then
    local player = getSpecificPlayer(0);
    local name = player:getForname();
    print("Player name: " .. name);
    player:Say(name);
end
end

 

 

I've attached the console message with the player name, along with my character's actual name. I am playing single player sandbox.

 

Any help would be greatly appreciated, as I'm thoroughly confused!

post-22763-0-40835600-1432492891_thumb.p

Link to comment
Share on other sites

Well, let's see what ctrl + f says:

            if instanceof(o, "IsoPlayer") then                self.objectView:addItem("Player: ".. o:getDescriptor():getForename() .. " "..  o:getDescriptor():getSurname(), o);            end
So, it looks like you have to get the descriptor from IsoPlayer, then get the name from that.
Link to comment
Share on other sites

Well, let's see what ctrl + f says:

 

            if instanceof(o, "IsoPlayer") then                self.objectView:addItem("Player: ".. o:getDescriptor():getForename() .. " "..  o:getDescriptor():getSurname(), o);            end
So, it looks like you have to get the descriptor from IsoPlayer, then get the name from that.

 

 

Thank you for your reply! It worked perfectly.

 

Slightly confusing as the documentation for the descriptor has a getForename() method, whilst the IsoPlayer has a getForname method. The spelling difference caused a few null errors when calling the wrong method by accident.  :shock:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...