I want to patch lightning strikes. My main problem is that I don't know how to create a variable and give it a starting value at the beginning of the flashstorm. Then this variable would change value during the flashstorm. At the beginning of another flashstorm it would be reset.
namespace Mod
{
[HarmonyPatch(typeof(GameCondition_Flashstorm), "GameConditionTick")]
public static class GameCondition_Flashstorm_GameConditionTick_Patch
{
static int nextCheckTicks = 0;
static bool doThisOncePerFlashstorm = true;
public static void Postfix(GameCondition_Flashstorm __instance)
{
if (doThisOnePerFlashstorm)
{
longStuff;
doThisOnePerFlashstorm = false;
}
if (Find.TickManager.TicksGame >= nextCheckTicks)
{
nextCheckTicks = Find.TickManager.TicksGame + 1000;
}
}
}
}
My issue is: nextCheckTicks does not reset to 0 at the next flashstorm neither does doThisOncePerFlashstorm turns false.
Thank you.
Also patch Init() to set your variable to 0?
Genius. I'm so dumb hahahah
My variables carry between harmony patches? Or this one carries because both methods are inside the same GameCondition_Flashstorm?
Edit:
Is there a way to do it? I can't seem to assign values to variables from another harmonypatch
Edit:
Managed to do it. Set the variable to public and call it by
GameCondition_Flashstorm_GameConditionTick_Patch.werePawnsChecked = false;
Inside the other patch
Yep; public static variable :) Which you figured out - you got this!