Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Combine Callback with Random Integers
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#1
Combine Callback with Random Integers

I'm working on a large combining script that uses items that randomly appear. When I was testing the scripts with the "_1" items, it worked fine, but now that I've implemented the "_2" and "_3" items, the only items that will combine are ones that share the same suffix.

Is there a way to fix this so that any item, no matter the suffix, can be combined with each other? Or is this an impassible bug?

This code is located in the inventory.hps and it does work in some cases. I've checked spellings and such. It only works with matching suffixes.

void OnGameStart()
{
    for(int i = 1; i <= 3; i++)
    {
        AddCombineCallback("VermillionLiquid", "mercury_"+i, "sulfur_"+i, "Liquid", true);
        AddCombineCallback("VermillionLiquidInJar", "paint_"+i, "liquidvermillion", "LiquidInJar", true);
        
        AddCombineCallback("Binder+Solvent", "linseed_"+i, "turpentine_"+i, "PaintA", true);
        AddCombineCallback("Solvent+Pigment", "turpentine_"+i, "refinedvermillion", "PaintB", true);
        AddCombineCallback("Pigment+Binder", "refinedvermillion", "linseed_"+i, "PaintC", true);
        
        AddCombineCallback("BinderSolventM+Pigment", "BinderSolvent", "refinedvermillion", "PaintD", true);
        AddCombineCallback("SolventPigmentM+Binder", "SolventPigment", "linseed_"+i, "PaintE", true);
        AddCombineCallback("PigmentBinderM+Solvent", "PigmentBinder", "turpentine_"+i, "PaintF", true);
    }
}

03-24-2018, 08:16 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: Combine Callback with Random Integers

I have done the below assuming wildcards (e.g. "Liquid_*") are not applicable to combine callbacks.

I made a very small program in VB.Net which mimics your loop and you'll find that the reason it only provides you with matching suffixes being combined is because, if you were to just test VermilionLiquid, it would output this:

Combine Callback: VermillionLiquid || Liquid_1 and sulfur_1 created!
Combine Callback: VermillionLiquid || Liquid_2 and sulfur_2 created!
Combine Callback: VermillionLiquid || Liquid_3 and sulfur_3 created!

The reason for this is i accounting for the same value in your loop - thus, when you step through the loop, for example, by writing it out on a piece of paper and writing the output down, you'll find that i provides the same suffix to both items in the line, as opposed to stepping through and doing a different value for each.

To fix this, we can use a second loop inside of the loop to account for our second value, as seen here:

Spoiler below!
Combine Callback: VermillionLiquid || Liquid_1 and sulfur_1 created!
Combine Callback: VermillionLiquid || Liquid_1 and sulfur_2 created!
Combine Callback: VermillionLiquid || Liquid_1 and sulfur_3 created!
Combine Callback: VermillionLiquid || Liquid_2 and sulfur_1 created!
Combine Callback: VermillionLiquid || Liquid_2 and sulfur_2 created!
Combine Callback: VermillionLiquid || Liquid_2 and sulfur_3 created!
Combine Callback: VermillionLiquid || Liquid_3 and sulfur_1 created!
Combine Callback: VermillionLiquid || Liquid_3 and sulfur_2 created!
Combine Callback: VermillionLiquid || Liquid_3 and sulfur_3 created!


To accomplish this, we just need a second value, and for simplicity, let's call it j. What j will do is be our second required value, and will start at 1, then become 2, then 3 at the end of its for-loop, while i stays at 1 and increments at the end of the code.

After a bit of cleanup, this should do it.

PHP Code: (Select All)
void OnGameStart()
{
    for(
int i 1<= 3i++) 
    {
        for(
int j 1<= 3j++)
        {
            
AddCombineCallback("VermillionLiquid""mercury_"+i"sulfur_"+j"Liquid"true);
            
AddCombineCallback("Binder+Solvent""linseed_"+i"turpentine_"+j"PaintA"true);
        }
        
        
AddCombineCallback("VermillionLiquidInJar""paint_"+i"liquidvermillion""LiquidInJar"true);
        
        
AddCombineCallback("Solvent+Pigment""turpentine_"+i"refinedvermillion""PaintB"true);
        
AddCombineCallback("Pigment+Binder""refinedvermillion""linseed_"+i"PaintC"true);
        
        
AddCombineCallback("BinderSolventM+Pigment""BinderSolvent""refinedvermillion""PaintD"true);
        
AddCombineCallback("SolventPigmentM+Binder""SolventPigment""linseed_"+i"PaintE"true);
        
AddCombineCallback("PigmentBinderM+Solvent""PigmentBinder""turpentine_"+i"PaintF"true);
        }
    }


Assuming of course that the Combine Callbacks which are outside of the "j" for-loop were working as intended before, this should fix it.

This can of course be changed if items are added/removed by simply incrementing/lowering both i and j as necessary, so the structure is fairly universal if others want to replicate the idea.

Also, for understanding sake, here is the code in VB.Net used to output the second set of results earlier. The first can be replicated by commenting out lines 10, 12 and 13.

edit: i made a pretty big logic error in this code and I truly, madly, deeply thank mudbill from the bottom of my heart for picking it up. xo

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 03-24-2018, 03:41 PM by Romulator.)
03-24-2018, 03:29 PM
Find
AGP Offline
Senior Member

Posts: 448
Threads: 45
Joined: Dec 2012
Reputation: 23
#3
RE: Combine Callback with Random Integers

Once again, Rom, you are a life saver! Big Grin

03-25-2018, 12:38 AM
Find




Users browsing this thread: 2 Guest(s)