KSP-ModularManagement / ModuleManager

ModuleManager is a mod that let you write patches that edit other parts at load time.
http://ksp.lisias.net/add-ons/ModuleManager
GNU General Public License v3.0
11 stars 5 forks source link

Help with math conflicts #13

Closed VexyCats closed 2 years ago

VexyCats commented 2 years ago

I get this error

[ERR 21:21:40.782] Error - Failed to do a maths replacement: @CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL : original value="50" operator=Multiply mod value="Random(@BluedogDB:Kerbucks05,@BluedogDB:Kerbucks075)

It seems to be a typing issue, where "50" is either a string or double, yet "Random()" is..... i dont know what? A function that returns a int or a string?

The code for BludDogDB:Kerbucks is here:


    DATA
    {
        type = double
        Kerbucks = ((( HomeWorld().Radius() / 1000 ) * 10) * 100)
        ....all more KerbucksXXX with different values

So my question is, why does my code here, fail to work to multiply whatever value the kerbucks is set to, by 100?


@CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL
{

    %addedCost1 = 50
    %addedCost = 100
    @addedCost1 *= #$advanceFunds$
    @advanceFunds = #$addedCost1$
    @addedCost *= #$rewardFunds$
    @rewardFunds = #$addedCost$
}
@CONTRACT_TYPE[*]:HAS[#rewardFunds&~#advanceFunds]:FINAL
{

    %addedCost = 100

    @addedCost *= #$rewardFunds$
    @rewardFunds = #$addedCost$
}
@CONTRACT_TYPE[*]:HAS[~#rewardFunds&#advanceFunds]:FINAL
{

    %addedCost = 100

    @addedCost *= #$advanceFunds$
    @advanceFunds = #$addedCost$
}

@Contracts[*]:HAS[@Funds[*]]:FINAL
{
   @Funds
   {
        @BaseReward *= 50
        @BaseAdvance *= 35
    }
}
@Contracts[Test]:HAS[@Funds[*]]:FINAL
{

   @Funds
   {
        @BaseReward *= 50
        @BaseAdvance *= 35
    }
}

@Contracts[*]:HAS[!@Funds,#rewardFunds,#advanceFunds]:FINAL
{

        @rewardFunds *= 50
        @advanceFunds *= 50

}

Note I have multiple statements for multiple mods and structures. But ultimately the main errors are:

[LOG 21:21:40.782] Applying update ZachsCash/contractChanges/@CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL to Bluedog_DB/Contracts/BDB_Corona_KH4.cfg/CONTRACT_TYPE[BDB_Corona_KH4]
[ERR 21:21:40.782] Error - Failed to do a maths replacement: @CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL : original value="50" operator=Multiply mod value="Random(@BluedogDB:Kerbucks05,@BluedogDB:Kerbucks075)"
[ERR 21:21:40.783] Error - Failed to do a maths replacement: @CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL : original value="100" operator=Multiply mod value="Random(@BluedogDB:Kerbucks105,@BluedogDB:Kerbucks2)"
[LOG 21:21:40.783] Applying update ZachsCash/contractChanges/@CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL to Bluedog_DB/Contracts/BDB_Gambit.cfg/CONTRACT_TYPE[BDB_Gambit]
[ERR 21:21:40.783] Error - Failed to do a maths replacement: @CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL : original value="50" operator=Multiply mod value="Random(@BluedogDB:Kerbucks075,@BluedogDB:Kerbucks1)"

and this for non-kerbucks

[LOG 21:21:40.789] Applying update ZachsCash/contractChanges/@CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL to ContractPacks/KerbinSideRemasteredGAP/Flights/06 - CommercialMultiFlights1.cfg/CONTRACT_TYPE[KSRGAP06-CommercialMultiFlights1]
[ERR 21:21:40.789] Error - Failed to do a maths replacement: @CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL : original value="50" operator=Multiply mod value="(@/rewardFunds * 0.25 )"
[ERR 21:21:40.789] Error - Failed to do a maths replacement: @CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL : original value="100" operator=Multiply mod value="((500000 + @KSRGAP:siteFltDistance.ElementAt(@/fltLocationSelection) + (200 * @/numPassengers )) * Random(1.0, 1.15)) * 2"
[LOG 21:21:40.789] Applying update ZachsCash/contractChanges/@CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL to ContractPacks/KerbinSideRemasteredGAP/Flights/07 - CommercialMultiFlights2.cfg/CONTRACT_TYPE[KSRGAP07-CommercialMultiFlights2]
[ERR 21:21:40.789] Error - Failed to do a maths replacement: @CONTRACT_TYPE[*]:HAS[#rewardFunds&#advanceFunds]:FINAL : original value="50" operator=Multiply mod value="(@/rewardFunds * 0.25 )"

Any help on why this is? Been working on it for a week now and I'm stuck.

VexyCats commented 2 years ago

@Lisias any help would be greatly appreciated.

VexyCats commented 2 years ago

Also it takes me 30 mins to load the game, so for simple changes in syntax .cfg files its superrrrrrrrrr painful. Even alt-f11 takes 20 minutes. Any suggestion to test live changes for reward values without the long waiting times for loading many mods?

Lisias commented 2 years ago

Hi, @VexyCats . Module Manager doesn't really do any math, other than basic operations (and in a somewhat convoluted way).

What's happening is that DBD is setting a value called Kerbucks with the String "((( HomeWorld().Radius() / 1000 ) * 10) * 100)" . DBD then reads this string and interprets it internally somehow, neither KSP neither ModuleManager knows squat about what really means "((( HomeWorld().Radius() / 1000 ) * 10) * 100)".

So, if you try to tell ModuleManager to use the value Kerbucks on some math operation, it will bork because for all effects, the value of Kerbucks is a mere string.

There's no way to use the Kerbucks evaluated value at all, this value is calculated by DBD at runtime only - way after the patching phase.

VexyCats commented 2 years ago
((( HomeWorld().Radius() / 1000 ) * 10) * 100)"

This is simply kerbucks = (600km (kerbin radius)) /100 *100

So the code:

@CONTRACT_TYPE[*]:HAS[#Kerbucks[*]]:FINAL
    %addedCost = 100

    @addedCost *= #$Kerbucks$
    @rewardFunds= #$addedCost$

Would find all contract types with any kerbucks* wildcard (ie: kerbucks5, kerbucks75) and then I can use that to multiply by 100?

Is this right?

Otherwise I'll just have to go replace all kerbucks = "" with a numerical value but thats a pain....

Lisias commented 2 years ago

@VexyCats

This is simply kerbucks = (600km (kerbin radius)) /100 *100

Nope. This is valid only for Stock - different planet packs will have different values for HomeWorld().Radius() and this is the reason the Contract Configurator maintainer choose to do things this way!

Would find all contract types with any kerbucks* wildcard (ie: kerbucks5, kerbucks75) and then I can use that to multiply by 100?

No, because you are still trying to multiply a number to a String!

Otherwise I'll just have to go replace all kerbucks = "" with a numerical value but thats a pain....

Or you can make the Contract Configurator to work for you! By reading the Contract Configurator manual you will find that it understands these expressions on many values, so perhaps you can just write:

     @rewardFunds= 100 * ( #$Kerbucks$ )

This will make rewardFunds to 100 * ( ((( HomeWorld().Radius() / 1000 ) * 10) * 100) ) and at runtime CC will compute the right value for you!

Lisias commented 2 years ago

@VexyCats it worked? Can I close this issue?

Lisias commented 2 years ago

Closing this as I assumed the problem was solved.