This commit is contained in:
Layla 2020-09-05 16:46:54 -04:00
parent 8dc142b907
commit 5696ac5574
2 changed files with 11 additions and 8 deletions

View File

@ -112,10 +112,6 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
logger.Info("Ran loadplayer method!")
if loadPlayerErr != nil {
logger.Error(loadPlayerErr.Error())
player.X = 16
player.Y = 16
} else {
logger.Error(loadPlayerErr.Error())
player = &entities.PlayerEntity{
X: 16,
@ -123,6 +119,13 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
Name: "ERROR",
Presence: precense,
}
} else {
if player != nil {
player.X = 16
player.Y = 16
} else {
logger.Error("Tried to access nil player object!")
}
}
logger.Info("Successfully loaded player object from storage!")

View File

@ -54,7 +54,7 @@ func PlayerDataExists(ctx context.Context, nk runtime.NakamaModule, userID strin
// LoadPlayer creates player object
func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.Presence) (*PlayerEntity, error) {
player := PlayerEntity{Presence: presence}
player := &PlayerEntity{Presence: presence}
// Read storage
PlayerReads := []*runtime.StorageRead{
@ -66,7 +66,7 @@ func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.P
}
records, err := nk.StorageRead(ctx, PlayerReads)
if err != nil {
return &player, err
return player, err
}
// Load storage records into object
@ -76,7 +76,7 @@ func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.P
responseData := PlayerSaveData{}
err := json.Unmarshal([]byte(record.Value), &responseData)
if err != nil {
return &player, err
return player, err
}
player.Name = responseData.Name
player.Faction = gameworld.Faction(responseData.Faction)
@ -84,7 +84,7 @@ func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.P
player.Y = 16.0
}
}
return &player, nil
return player, nil
}
// GetPosJSON returns the player's position as a JSON object