How to change players?

Is there any tutorial or examples on how to change players from an option screen and have the selected player show up on the game screen? I don’t know how I should approach it codewise. I tried to look at TiltMonster for an example but I just get lost reading it and I can’t really find anything about player selection. What’s a method of doing it? [import]uid: 114389 topic_id: 26898 reply_id: 326898[/import]

What I would do is have all my players and their information stored in a table, likely using their name as the key. Say you have 2 players in the table, you’d create a button for each, likely using the name as part of the button text.
Then when you press the button, you know which set of data to use for your game.

So if you wanted to track the score and lives per player, for each player you’d add:

{ score = 0, lives = 5 }

So say you have Barry and Tom already set up (easy to add / remove players too, since it is just adding or removing entries from the table), then your base data structure would be something like:

local playersData = {
Barry = { score = 0, lives = 5 },
Tom = { score = 12300, lives = 2 }
}

then you’d get at an individual player’s data with:

local playerData = playersData[“Barry”]

or

local playerData = playersData[“Tom”]

Rinse and repeat for any other actual names.

To actually save and load this data to maintain it between sessions, you’ll likely want to look at one of the demos that ships with Corona in the ‘storage/’ folder in the sample codes. [import]uid: 46639 topic_id: 26898 reply_id: 109164[/import]

I appreciate your help and am going to use it! But I think I didn’t describe it well. Instead of players, I meant “Characters”. For example if you can choose to play as a snowboarder or skier, guy or girl. Or is your explanation work for that such as

local playerData = playersData[“Character1”]
local playerData = playersData[“Character2”]

[import]uid: 114389 topic_id: 26898 reply_id: 109273[/import]

I’m working on a game that requires different characters for certain levels. It’s similar so maybe it’ll help you. I’ve approached it by creating a table of character specific initializers, like this:

[code]
function new(options)

initializers = {

[‘character1’] = function()

– Define sprite sheets etc…

– Add the sprite sheet to the character
self.avatar = sprite.newSprite(sprite_set)
self.avatar:setReferencePoint(display.BottomCenterReferencePoint)

– Create the Avatar Physics Body
squareShape = { -15,-40, 15,-40, 15,45, -15,45 }
sensorShape = { -12,40, 12,40, 12,50, -12,50 }
physics.addBody(self.avatar,
{density = .5, friction = 0, bounce = 0, shape = squareShape, filter = self.avatar_collision_filter },
{density = .5, friction = 0, bounce = 0, shape = sensorShape, radius = 10, isSensor = true, filter = self.avatar_collision_filter}
)
self.avatar.angularDamping = 100
self.avatar.isFixedRotation = true

– Physical Powers / Attributes
self.maxX = 300
self.jumpPower = 35
end,
[‘character2’] = function()
– Character 2 specific stuff
end,
}

– Run the initializer for the particular avatar
initializersoptions.type;

– Other stuff

end[/code]

This is really similar to what rakoonic said. [import]uid: 136876 topic_id: 26898 reply_id: 109287[/import]