Using Update Query instead of global Variable

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Using Update Query instead of global Variable

      I am not 100% sure about this but did anyone notice that this piece of code:


      PHP Source Code

      1. if($PLANET['id'] == WHATEVER_END_ID_OF_A_PLANET_OR_SOMETHING_ELSE) {
      2. $PLANET[$resource[901] += SOME_NUMBER;
      3. } else {
      4. database::get()->update("UPDATE %%PLANETS%% SET metal = :currentMetal + :newMetal WHERE id = :planetId", [
      5. ':currentMetal' => $PLANET['metal'],
      6. ':newMetal' => SOME_NUMBER,
      7. ':planetId' => $PLANET['id']
      8. ]);
      9. }
      that its just more efficient as i faced resource looses caused by probably invalid rows of updates by the PlanetRessUpdate class and this one.

      I mean if i only use the code used at else and i am on this planet, i sometimes face resource looses.

      Those Resources Looses not only happened on Flights - also on Features for example, so i wonder if somebody else may encountered this.
    • есть какая то разница? кроме того что ты будешь делать 3 запроса вместо 1, значит нагрузка на базу вырастит в несколько раз.

      что ты хочешь

      PHP Source Code

      1. <?php
      2. database::get()->update("UPDATE %%PLANETS%% SET metal = :currentMetal + :newMetal WHERE id = :planetId", [
      3. ':currentMetal' => $PLANET['metal'],
      4. ':newMetal' => SOME_NUMBER_1,
      5. ':planetId' => $PLANET['id']
      6. ]);
      7. $PLANET['metal'] += SOME_NUMBER_1;
      8. database::get()->update("UPDATE %%PLANETS%% SET metal = :currentMetal + :newMetal WHERE id = :planetId", [
      9. ':currentMetal' => $PLANET['metal'],
      10. ':newMetal' => SOME_NUMBER_2,
      11. ':planetId' => $PLANET['id']
      12. ]);
      13. $PLANET['metal'] += SOME_NUMBER_2;
      14. database::get()->update("UPDATE %%PLANETS%% SET metal = :currentMetal + :newMetal WHERE id = :planetId", [
      15. ':currentMetal' => $PLANET['metal'],
      16. ':newMetal' => SOME_NUMBER_3,
      17. ':planetId' => $PLANET['id']
      18. ]);
      19. $PLANET['metal'] += SOME_NUMBER_3;
      20. ?>
      Display All

      что сейчас

      PHP Source Code

      1. <?php
      2. $PLANET['metal'] += SOME_NUMBER_1;
      3. $PLANET['metal'] += SOME_NUMBER_2;
      4. $PLANET['metal'] += SOME_NUMBER_3;
      5. database::get()->update("UPDATE %%PLANETS%% SET metal = :currentMetal WHERE id = :planetId", [
      6. ':currentMetal' => $PLANET['metal'],
      7. ':planetId' => $PLANET['id']
      8. ]);
      9. ?>
      Display All
    • как мне кажется надо все запросы с ресурсами объединить в 1 запрос тогда потерь ресурсов не будет, т.е все манипуляции с ресурсами должны быть только в PlanetRessUpdate.
    • si, he notado que un tiempo paso mucho, en mi servidor los usuarios me reportaban muchas perdidas de recursos, sobre todo en vuelos, llegaban pero no entregaban los recursos.. y era algo con PlanetRessUpdate porque me daba un error en los log de errores
    • XenQen wrote:

      I am not 100% sure about this but did anyone notice that this piece of code:


      PHP Source Code

      1. if($PLANET['id'] == WHATEVER_END_ID_OF_A_PLANET_OR_SOMETHING_ELSE) {
      2. $PLANET[$resource[901] += SOME_NUMBER;
      3. } else {
      4. database::get()->update("UPDATE %%PLANETS%% SET metal = :currentMetal + :newMetal WHERE id = :planetId", [
      5. ':currentMetal' => $PLANET['metal'],
      6. ':newMetal' => SOME_NUMBER,
      7. ':planetId' => $PLANET['id']
      8. ]);
      9. }
      that its just more efficient as i faced resource looses caused by probably invalid rows of updates by the PlanetRessUpdate class and this one.

      I mean if i only use the code used at else and i am on this planet, i sometimes face resource looses.

      Those Resources Looses not only happened on Flights - also on Features for example, so i wonder if somebody else may encountered this.

      Either is equal in their own cases. What happens is when user active planet is updated, the update of elements are handled by classplanetressupdate forced by abstractgamepage. There are no invalid rows on it, just how it works.

      Using DB UPDATE for elements on $reslistarray FOR user CURRENTLY ACTIVE planet won't work because at the end the ecoObj will overwrite your request and save current ResourceUpdate() request into database. [ecoObj = ResourceUpdate()->CalcResource($USER, $PLANET), do your stuff $USER += something or $PLANET += something, ecoObj->save()]

      This saying, if you want to store user data on the planet he is and it's related with $reslist elements or it's an external request (like resource transfer, check resources from spy mission...) that calls a planet with ResourceUpdate class, then you use $PLANET[someresource] += value (on external case, you need to $class->saveplanettodb() ).

      Otherwise, if is a planet he is not active or its not related with $reslist elements, you use database call. Because thats how AbstractGamePage works and how players requests are handled.

      This explains why $PLANET[something] works in some cases and not in anothers. More details into ResourceUpdate->SavePlanetToDB()




      * to clarify who does not get ResourceUpdate, it's the class name for class.PlanetRessUpdate.
      Looking for good VPS to host your game? Use DigitalOcean and get 100$ bonus credit for 2 months!

      Check my mods here - stellaron.space/index.php?page=2Moons

      I can build any mod. Need my service? Contact me via PM

      The post was edited 4 times, last by Qwa ().

    • yamilrh wrote:

      Alguna forma para solucionar dichas perdidas?
      Nothing is lost if you're using vanilla game. Now if you have external modules you've made (or you're developing) that requires changes on resources, buildings or ships, you must take care if the change is for the current planet or to all planets (in case of all planets you need both $PLANET[$resource[ID]] or $PLANET[metal] += value FOR CURRENT REQUESTED PLANET BY PLAYER AND database update for other colonies of player).

      Is that too confusing? At start yes, if you don't have much experience, but you get used to it. If you don't like, then you need to write by yourself a new class.planetressupdate or remove ecoObj from AbstractPage, which I do not recommend.
      Looking for good VPS to host your game? Use DigitalOcean and get 100$ bonus credit for 2 months!

      Check my mods here - stellaron.space/index.php?page=2Moons

      I can build any mod. Need my service? Contact me via PM

      The post was edited 3 times, last by Qwa ().