SetImageRotation (Resolved)

Started by GoodMorning, June 18, 2016, 09:42:25 AM

Previous topic - Next topic

GoodMorning

Hello all,

Could someone take a look at this?
It's part of a Bertha-like unit, but when I reapply the script to a core, the sub-images are not returned to their standard orientation.
The relevant blocks are below, and they are each run at least once before I have the problem.

This is in the once block at the top of the code, and is what I thought should reset the orientation.

  Self "Generator" "Custom1_128" SetImage
  Self "PowerCell" "Custom0_128" SetImage
  0 asfloat ->MainRotation
  Self 0 "Generator" SetImageRotation
  Self 0 "PowerCell" SetImageRotation
  Self "Generator" -0.045 SetImagePositionZ
  Self "PowerCell" -0.05 SetImagePositionZ
  Self "PowerCell" 255 255 255 0 SetImageColor


This is the main rotating function, adapted from a combination of the CBeam and CBertha.

:Rotate
  <-TargetX <-TargetY CellToPixel ->BM_PY ->BM_PX

  Self CONST_PIXELCOORDX GetUnitAttribute ->BM_SX
  Self CONST_PIXELCOORDY GetUnitAttribute ->BM_SY

  <-BM_PX <-BM_SX sub ->BM_DX
  <-BM_PY <-BM_SY sub ->BM_DY
  <-BM_DY <-BM_DX atan2 ->BM_A

  <-MainRotation <-BM_A ShortestAngle ->RotationToMake

  <-RotationToMake <-TurnSpeed gt if
<-TurnSpeed ->RotationToMake
  else
<-RotationToMake <-TurnSpeed neg lt if
  <-TurnSpeed neg ->RotationToMake
endif
  endif

  <-MainRotation <-RotationToMake add ->MainRotation

  Self "Generator" <-MainRotation SetImageRotation
  Self "PowerCell" <-MainRotation SetImageRotation

  <-RotationToMake abs 0.0001 lt #Close enough
A narrative is a lightly-marked path to another reality.

planetfall

The SetImageRotation in your once block has the arguments in the wrong order. Self 0 "Generator" instead of Self "Generator" 0.

Also note that it's probably best* to put initialization code in an awake function, with redundant onces to reapply it on recompile. Though that usually hardly matters unless you're going to be spawning the core during gameplay.

Example:


once
    @awake
endonce

#main script behavior

:awake
    once
        #initialize
    endonce


*best = best for the way I think and organize scripts. Your mileage may vary.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

Builder17

Doesn't :Awake call itself automatically when core with it is created and when game is loaded?  ???

@Awake in once block isn't needed.   :o

planetfall

Quote from: Builder17 on June 18, 2016, 11:04:55 AM
Doesn't :Awake call itself automatically when core with it is created and when game is loaded?  ???

@Awake in once block isn't needed.   :o

Correct. But you may want the awake function to run again after recompiling while debugging scripts.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

GoodMorning

I seem to have lost something subtle:

Why is it that the once block is not recommended for initialisation?
For graphics, I can understand use of :awake, if sub-images are not preserved, but everything else seems to work properly...

I haven't encountered issues when using this with script-created Cores, so I am wondering why this is relevant?
A narrative is a lightly-marked path to another reality.

planetfall

Quote from: GoodMorning on June 18, 2016, 09:54:03 PM
I seem to have lost something subtle:

Why is it that the once block is not recommended for initialisation?
For graphics, I can understand use of :awake, if sub-images are not preserved, but everything else seems to work properly...

I haven't encountered issues when using this with script-created Cores, so I am wondering why this is relevant?

This is something I ran into on an older map. I had a core spawning projectiles, which would each have CONST_NULLIFIERDAMAGES set to false in a once block. However, this led to there being one frame on which the projectile was vulnerable to nullifiers. :awake is run on the same frame as the core is spawned, while the main body of the script runs the next frame. You can just as easily set all the CONST's using the script that spawns it, though. Additionally some esoteric things don't persist across saves (like CONST_SHOWHEALTHBAR, SetScreenMode and OperateWhilePaused.) Since those have to be reinitialized via :awake each time anyway, I just find it easier to put everything init-y there.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

GoodMorning

Fair, up until you are setting defaults, at which point, say, MainRotation becomes 0, altering the firing cycle.

Thanks for that.
A narrative is a lightly-marked path to another reality.