Question about Scale behavior

I’m trying to use Scale with IncrementWithReset function, to create a swing effect that builds up with each Clash, and releases with the next Lockup.

So, I have an Effect using AlphaL, and this is the function im using for the alpha:

						Scale<
							IncrementWithReset<
								EffectPulseF<EFFECT_CLASH>,
								Sum<
									EffectPulseF<EFFECT_CLASH>,
									EffectPulseF<EFFECT_LOCKUP_BEGIN>
								>,
								Int<32768>,
								Int<2000>
							>,
							Int<0>,
							Int<24576>
						>

The idea is to have each Clash increase the opacity of the effect, until it reaches 75% opacity max (Int<24576>)

If i’m understanding IncrementWithReset correctly, what I have should increase the value by 2000 each CLASH.

However, the resulting code in testing, starts out invisible as it should, but becomes the full 75% opacity on the first Clash. It properly resets to invisible on Lockup. So, not sure what i’m doing wrong here. Maybe i’m using Scale incorrectly?

I’m not sure why you’re using Scale. Seems like what you want is just:

IncrementWithReset<
  EffectPulseF<EFFECT_CLASH>,
  EffectPulseF<EFFECT_LOCKUP_BEGIN>,
  Int<24576>,
  Int<1500>
>

(I inlined the scaled values into IncrementWithReset)

Also, when I tried yours in the style editor, it would recent immediatly since you have CLASH in both the trigger and the reset part…

This works as intended in the style editor at least, hopefully it will also work in a real saber… :slight_smile:

1 Like

ok cool.

Next, I want to make a “build up release” effect flash occur when EFFECT_LOCKUP_BEGIN happens, and it’s intensity is also based on the same formula. So, the more “energy” is built up from clashes, the brighter the flash on lockup start.

I wish there were Variables that the STYLE code could store/set, and that could be used elsewhere in the code.

Like, I would want to say:

SetStyleVar1<
	IncrementWithReset<
		EffectPulseF<EFFECT_CLASH>,
		EffectPulseF<EFFECT_LOCKUP_BEGIN>
		Int<32768>,
		Int<2000>
	>
>

Then later say for the Swing Effect:

AlphaL<
	Layers<
		... Style here
   	>
	StyleVar1
>

and in the Lockup code have another invisible layer trigger for the flash that uses the same StyleVar1 for it’s transparency.

Styles really aren’t meant to be a programming language though.
It’s easier to just write some code, either in the prop, or a customized style if you want to achive these sort of things. Then you can have variables, and all the power of C++ to do whatever you want.

Of course, this requires programming, but what you are trying to do with styles is also programming.

Maybe I’ve just no clue where it is, but some documentation on the Style front would be awesome.

2 Likes

Awesome, thank you much!

So, i’m trying to make a bump that starts small and expands to the full length of the blade, using the Style Builder website for the first time.

https://fredrik.hubbe.net/lightsaber/style_editor.html?S=TransitionEffectL<TrConcat<TrWaveX<AlphaL<White%2CBump<Int<16384>%2CPercentage<TimeSinceEffect<EFFECT_BLAST>%2C10000>>>>%2CWhite%2CTrWipe<50>>%2CEFFECT_BLAST>

I got TimeSinceEffect and am scaling it up with Percentage, but when i get it fast enough, it seems to not peak out at full size, but instead loops back to small and then back and forth a few times :-/

Basically trying to make something similar to TrWaveX, but stays full in the center as it expands, like a Bump.

Here is a small chunk of (untested) code you can use to make something charge up and release it.
(I think that’s what you are trying to do here.)

#ifdef CONFIG_STYLES
class ChargeAccumulator : public SaberBase {
 public:
   void reset() { charge_ = last_charge_ = 0; }
  void SB_Effect(EffectType effect, float location) override {
     switch (effect) {
         case EFFECT_CLASH:
            charge_ = std::max(charge_ + 1500, 24576);
            break;
         case EFFECT_LOCKUP_BEGIN:
            last_charge_ = charge_;
            charge_ = 0;
     }
  }
   uint32_t charge_;
   uint32_t last_charge_;
};

ChargeAccumulator charge_accumulator;

class CurrentChargeF {
public:
   CurrentChargeF() { charge_accumulator_.reset(); }
   void run(BladeBase* blade) {}
   int getInteger(int led) { return charge_accumulator.charge_; }
};

class LastChargeF {
public:
   LastChargeF() { charge_accumulator_.reset(); }
   void run(BladeBase* blade) {}
   int getInteger(int led) { return charge_accumulator.last_charge_; }
};

#endif

With this you can use CurrentChargeF and LastChargeF as styles, and I think they will do what you actually want.

How about something like:

Remap<
  CenterDistF<>,
  TransitionEffectL<
     TrConcat<TrWipe<2000>,White,TrInstant>,
     EFFECT_BLAST
  >
>

Yea, that Remap seems to be pretty much what I’m after. Here’s the final code for Lockup Release flash in style editor.

https://fredrik.hubbe.net/lightsaber/style_editor.html?S=Remap<CenterDistF<>%2CTransitionEffectL<TrConcat<TrWipe<300>%2CAlphaL<White%2CIncrementWithReset<EffectPulseF<EFFECT_CLASH>%2CEffectPulseF<EFFECT_LOCKUP_BEGIN>%2CInt<32768>%2CInt<4096>>>%2CTrFade<300>>%2CEFFECT_LOCKUP_BEGIN>>