TemKa_SD Posted August 27, 2018 Share Posted August 27, 2018 Здравствуйте. Почему не возвращает значения из \IPS\sharedstats\Records\ScoredGame? /** * @param array $game * @param string $type * @return StatsGamesScored */ protected function createGameEntity(array $game, $type): \IPS\sharedstats\Records\ScoredGame { $scoredGame = new \IPS\sharedstats\Records\ScoredGame(); #$scoredGame->gameid = $game['id']; $scoredGame->setGameid($game['id']); $scoredGame->setGamename($game['gamename']); $scoredGame->setDuration($game['duration']); $scoredGame->setUuid($game['uuid']); $scoredGame->setMap($game['map']); $scoredGame->setSaved(new \DateTime($game['datetime'])); $scoredGame->setScored(new \DateTime()); $scoredGame->setType($type); #$scoredGame->setTeam1win(50.00); #$scoredGame->setTeam2win(50.00); $scoredGame->setLobbyChats(json_encode([])); $scoredGame->setGameChats(json_encode([])); $scoredGame->setPlayerawards(json_encode([])); $scoredGame->setWinner(0); $scoredGame->save(); } Link to comment Share on other sites More sharing options...
newbie Posted August 28, 2018 Share Posted August 28, 2018 protected function createGameEntity(array $game, $type): \IPS\sharedstats\Records\ScoredGame {Вы указали, что должен вернуться объект класса \IPS\sharedstats\Records\ScoredGame, но ничего не возвращаете. $scoredGame->save(); return $scoredGame; Link to comment Share on other sites More sharing options...
TemKa_SD Posted August 28, 2018 Author Share Posted August 28, 2018 Вы указали, что должен вернуться объект класса \IPS\sharedstats\Records\ScoredGame, но ничего не возвращаете. Значит это не то. Я во всём разобрался, у меня всё отлично работает, данные собираются между функциями, сохраняются - всё отлично. Т.е если взять вот эту строку: $scoredGame->setGameid($game['id']); Работать не будет, функция не работает, она в прикрепленном файле. Если использовать значение передаваемое в таске между функциями то всё работает отлично: $scoredGame->gameid = $game['id']; Этот весь функционал с другого движка, на котором всё работало, помогите разобраться с функциями в файле ScoredGame, почему не возвращает нужные значения. Т.е если в функции прописать return 1; то вернет всё как надо, не работают именно переменные почему-то.ScoredGame.php Link to comment Share on other sites More sharing options...
newbie Posted August 28, 2018 Share Posted August 28, 2018 Что именно не работает? .е если в функции прописать return 1; то вернет всё как надо, не работают именно переменные почему-тоГде прописать? Link to comment Share on other sites More sharing options...
TemKa_SD Posted August 29, 2018 Author Share Posted August 29, 2018 Вот на скрине, если вернуть просто 1 то оно вернет, а через this не работает почему-то. Link to comment Share on other sites More sharing options...
newbie Posted August 29, 2018 Share Posted August 29, 2018 А дальше? Где Вы эту единицу используете? В каком конкретно месте происходит не то, что ожидаете? Link to comment Share on other sites More sharing options...
TemKa_SD Posted August 29, 2018 Author Share Posted August 29, 2018 $scoredGame->setGameid($game['id']); Link to comment Share on other sites More sharing options...
TemKa_SD Posted August 30, 2018 Author Share Posted August 30, 2018 Еще раз попробую объяснить. /** * @param array $game * @param string $type * @return StatsGamesScored */ protected function createGameEntity($game, $type): StatsGamesScored { $scoredGame = new StatsGamesScored(); #$scoredGame->gameid = $game['id']; $scoredGame->setGameid($game['id']); $scoredGame->setGamename($game['gamename']); $scoredGame->setDuration($game['duration']); $scoredGame->setUuid($game['uuid']); $scoredGame->setMap($game['map']); $scoredGame->setSaved(new \DateTime($game['datetime'])); $scoredGame->setScored(new \DateTime()); $scoredGame->setType($type); #$scoredGame->setTeam1win(50.00); #$scoredGame->setTeam2win(50.00); $scoredGame->setLobbyChats(json_encode([])); $scoredGame->setGameChats(json_encode([])); $scoredGame->setPlayerawards(json_encode([])); $scoredGame->setWinner(0); $scoredGame->save(); return $scoredGame; } Вот в этом коде возвращаем значения из файла - функций (StatsGamesScored)$scoredGame->setGameid($game['id']); Я пробую сейчас вернуть просто двойку, оно не возвращает, почему? /** * Set gameid * * @param integer $gameid * * @return StatsGamesScored */ public function setGameid($gameid) { return 2; } Link to comment Share on other sites More sharing options...
newbie Posted August 30, 2018 Share Posted August 30, 2018 Покажите, где Вы пытаетесь получить двойку Link to comment Share on other sites More sharing options...
TemKa_SD Posted August 30, 2018 Author Share Posted August 30, 2018 /** * @param array $game * @param string $type * @return StatsGamesScored */ protected function createGameEntity($game, $type): StatsGamesScored { $scoredGame = new StatsGamesScored(); #$scoredGame->gameid = $game['id']; $scoredGame->setGameid($game['id']); $scoredGame->setGamename($game['gamename']); $scoredGame->setDuration($game['duration']); $scoredGame->setUuid($game['uuid']); $scoredGame->setMap($game['map']); $scoredGame->setSaved(new \DateTime($game['datetime'])); $scoredGame->setScored(new \DateTime()); $scoredGame->setType($type); #$scoredGame->setTeam1win(50.00); #$scoredGame->setTeam2win(50.00); $scoredGame->setLobbyChats(json_encode([])); $scoredGame->setGameChats(json_encode([])); $scoredGame->setPlayerawards(json_encode([])); $scoredGame->setWinner(0); $scoredGame->save(); return $scoredGame; } Link to comment Share on other sites More sharing options...
newbie Posted August 30, 2018 Share Posted August 30, 2018 Этот код чуть ли не в каждом посте.$scoredGame->setGameid($game['id']);Здесь идет присваивание $scoredGame->gameid = $game['id'];Где Вы хотите получить двойку, не понятно. Чтобы получить двойку public function setGameid($gameid) { return 2; }и$two = $scoredGame->setGameid($game['id']);Тогда значение переменной $two будет 2 Link to comment Share on other sites More sharing options...
TemKa_SD Posted August 30, 2018 Author Share Posted August 30, 2018 (edited) Хорошо, вот такой код почему возвращает null? $scoredGame->setGameid($game['id']); /** * Set gameid * * @param integer $gameid * * @return StatsGamesScored */ public function setGameid($gameid) { $this->gameid = $gameid; return $this; } Edited August 30, 2018 by TemKa_SD Link to comment Share on other sites More sharing options...
newbie Posted August 30, 2018 Share Posted August 30, 2018 Хорошо, вот такой код почему возвращает null?Как Вы определяете, что NULL? Link to comment Share on other sites More sharing options...
TemKa_SD Posted August 30, 2018 Author Share Posted August 30, 2018 В БД идет стандартное значение "0" при сохранении $scoredGame->save();. Link to comment Share on other sites More sharing options...
newbie Posted August 30, 2018 Share Posted August 30, 2018 В БД идет стандартное значение "0" при сохранении $scoredGame->save();. Из-за protected $poolid; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now