Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Modified numbers stay modified after save?  (Read 1805 times)

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Modified numbers stay modified after save?
« on: December 04, 2015, 08:11:58 PM »

I am trying to mod the station tariffs...

I noticed that after I save a game after applying a modifyMult(), and load it again, the base value is changed, permanently.

Is this a bug, or actually intended behaviour?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24131
    • View Profile
Re: Modified numbers stay modified after save?
« Reply #1 on: December 04, 2015, 08:15:47 PM »

Yeah, that's how it works, except for fleet members, whose stats have to be modified from hullmods and the like

If you take a look at any of the market condition classes, you'll note that there's an unapply() method that unapplies whatever stat changes the condition makes, and that gets called when it's removed from a market.
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Modified numbers stay modified after save?
« Reply #2 on: December 04, 2015, 08:17:47 PM »

I saw that, what I am saying is that if I save the game, before using "unmodify", the BASE value changes.

thus if I mod a value for example by 0.5, and save repeteadly, each time I save it get divided in half.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24131
    • View Profile
Re: Modified numbers stay modified after save?
« Reply #3 on: December 04, 2015, 08:18:41 PM »

Hmm. Can you show me the code you're using?

Edit: for a quick test, I added to OrbitalStation:

apply():
market.getTariff().modifyMult(id, 0.5f);

unapply():
market.getTariff().unmodify(id);

It seems to be working properly, i.e. the tariff remains set at 15% regardless of how many times it's saved.
« Last Edit: December 04, 2015, 08:23:02 PM by Alex »
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Modified numbers stay modified after save?
« Reply #4 on: December 04, 2015, 09:09:12 PM »

I already modified my code a lot...

I did TWO things that fixed the bug, but I dunno what one was the real solution.

One thing, is that now I unapply stuff imediately after using the values I needed (ie: I apply when a market opens, and unapply when it closes).

the other thing is that now I use unmodify(id) instead of just unmodify()
Logged