I-rate conditionals executing after reinit

So pretty general question here, I have a reinit pass which reinitializes one of my variables to a different value than on the first init pass, however I noticed that after reinitializing this variable the conditionals which utilize this variable are still evaluating as true and executing the code within the statement despite the condition now being unmet. Is there any way to get the conditional statements to recognize the change and update their evaluation without simply calling the conditional evaluation to run at k-rate (which sort of defeats the purpose of having these variables at i-rate in the first place)?

Can you post a simple example? I rarely mess around with reinit, I find it utterly frightening :rofl:

Basically I’m doing something alone these lines:

iVariableToChange init 0
kModifyTrigger chnget "ModifyTrigger"
if(changed2:k(kModifyTrigger)==1) then
    reinit ConnectionModifierReceived
    ConnectionModifierReceived:
        iVariableToChange init 1
    rireturn
endif
if(iVariableToChange==1) then
    printks "Variable changed and conditional block now succeeds", 5.0
endif

I can obviously change it to k-rate for the conditional evaluation but as far as optimizing goes being able to simply have it re-evaluate the associated i-rate conditionals a single time after the reinit pass would be ideal. From what I remember about my courses in compiler design (its been years) I know this would be possible (difficult, but feasible), but from the fact that this does not seem to work I’m guessing that reinit was implemented with a different scope/use case in mind than this.

It being k-rate isn’t a huge deal in the particular context I’m using it in but I’m mostly just trying to keep the number of k-rate conditionals, variables, etc down so as the program keeps growing I don’t start hitting resource bottlenecks down the line.

If this outside of the scope of reinit’s intended functionality/use cases then any workarounds for this sort of thing would be great. If there currently aren’t any I can just try and get creative to try and keep the k-rate evaluations down somehow. Long term I may poke around the source of reinit and see how it operates and look into implementing a solution that might re-evaluate the i-rate conditionals on the first k-pass after reinit executes.

This is how I would handle this, but I’m not sure it works for your purposes:

ConnectionModifierReceived:
kModifyTrigger chnget "play"
iVariableToChange init i(kModifyTrigger)
printf_i "Variable changed %d", 1, iVariableToChange
if(changed2:k(kModifyTrigger)==1) then
    reinit ConnectionModifierReceived
endif

p.s. tell everyone on discord I say hi, and that they need to haul ass over here every now and then :rofl:

Will do, I hopped in there. The problem I am facing now is if it is possible to call chnset or chnget with values in a string array that updates at runtime. Currently I seem to be unable to do this. I can access the newly inserted values by using a k-rate accesor variable like Sarray[kIndx] but chnget and chnset don’t seem to be playing nicely with this as it seems to crash when I attempt to do so.

You should probably use the array variants of chnget/chnset?

I gave that a shot but with my current implementation it turned out looking kind of ugly so I decided to implement a system that uses the zak patching system. Seems muchhh better for my current use case and more reliable for realtime connection/disconnecting being it takes k-rate parameters as opposed to the channel operators string parameters. Thanks so much for the responses, really appreciate it.

1 Like