YesNoOk
avatar

What is preventing a piece of code from repeating itself extremely rapidly? (Read 91096 times)

Started by DNZRX768, May 16, 2023, 02:03:55 pm
Share this topic:
What is preventing a piece of code from repeating itself extremely rapidly?
#1  May 16, 2023, 02:03:55 pm
  • *****
  • Hug Pikachus!
    • USA
I was in the middle of looking over and reviewing New Pikachu's coding when I ran into this:

Code:
[State 6900, 4]
type = HitDef
trigger1 = Time >=0
attr = S, NA
animtype  = Medium
damage    = 20,0
guardflag = MA
pausetime = 0,0
sparkxy = -10,0
hitsound   = S2401,1
guardsound = 6,0
ground.type = High
ground.slidetime = 12
ground.hittime  = 15
ground.velocity = -5,0
air.velocity = -2.2,-3.2
persistent = 20
palfx.time = 45
palfx.add = 0,15,75
palfx.color = 0
palfx.invertall = 1
palfx.sinadd=255,255,255,4

It's the Hitdef for the Pikachu's Lighting Shield helper. I was curious: what is exactly preventing the shield from inflicting damage every millisecond? The shield inflicts damage every 3/4 second or so, based on my estimate, which is a far-cry from a damage-every-millisecond that I would expect from the trigger that was used for the coding, so there is something hidden in the background that slows down the damage pulses.

Code:
[Statedef -2]

;Used as a counter
[State -2, 1]
type = varadd
trigger1 = var(1) > 0
v = 1
value = 1

;Activated the shield explode effect every 8 ticks
[State -2, 2]
type = varadd
trigger1 = var(1) = 8
v = 2
value = 1

;read above
[State -2, 4]
type = varset
trigger1 = var(1) > 8
v = 2
value = 0

;Counter 'til shield expires
[State -2, 4]
type = varadd
trigger1 = var(1) > 8
v = 3
value = 1

;resets var(1)
[State -2, 3]
type = varset
trigger1 = var(1) > 8
v = 1
value = 1

My similar confusion on how and why the coding is not getting finished at a lighting pace also applies to this piece of coding the whole Pikachu's Lighting Shield setup seems to rely on. I am curious on what is preventing variable 3 to shoot up to 1000 or so in a blink of an eye. The whole thing is a counter, sure, but there is nothing in the coding that seems to prevent the program from running the cycles so many times in a blink of an eye...

Hug the Pikachus!

Hug A Pikachu Today!
Re: What is preventing a piece of code from repeating itself extremely rapidly?
#2  May 16, 2023, 03:34:03 pm
  • *****
  • Resident Tosspot
  • Pftheh
    • UK
    • plasmoidthunder.neocities.org
If the HitDef is within a Helper, it's possible the Helper isn't remaining in that state once it hits (either due to an interim state or DestroySelf). The rest of the code within that state will likely answer your question.

Regarding the -2 code, it runs once every tick, which is 1/60 of a second; to humour your example, var(3) would reach 1000 in just over 16.5 seconds, though the reason it doesn't is because it only increments when var(1) is more than 8, which in turn happens once every 9 ticks due to var(1) being set back to 0 immediately after var(3) increments.

Oh, I want a diagram. I fucking love diagrams.
Re: What is preventing a piece of code from repeating itself extremely rapidly?
#3  May 16, 2023, 05:19:35 pm
  • ******
    • Portugal
    • network.mugenguild.com/pots/
The first one is because it has "persistent = 20" in the middle of the block (which is bad practice).
You can help with Ikemen GO's development by trying out the latest development build and reporting any bugs on GitHub.
My Mugen and Ikemen content can also be found here.
Re: What is preventing a piece of code from repeating itself extremely rapidly?
#4  May 16, 2023, 08:39:08 pm
  • *****
  • Hug Pikachus!
    • USA
The first one is because it has "persistent = 20" in the middle of the block (which is bad practice).

What should be the recommended good practice then?
Hug the Pikachus!

Hug A Pikachu Today!
Re: What is preventing a piece of code from repeating itself extremely rapidly?
#5  May 17, 2023, 12:04:49 pm
  • *****
  • Shame on you!
    • USA

  • Online
At the bottom. Usually you'll see both
ignorehitpause = 1
persistent = 1
at the bottom of chunks of code. It's for making it easier to spot.
vVv Gouken718 vVv