Skip to content

add assignment (+=) operator does not always update value within progress block #328

@EnlightenedLegume

Description

@EnlightenedLegume

Short description

Using the add assignment (+=) operator does not produce the expected value /within/ a progress block. It appears that between iterations of a progress block the value is correct.

Minimal liftoscript reproducer

Squat / 3x5 / 3x3 / 3x1 / progress: custom() {~
  print(setVariationIndex)
  setVariationIndex += 1
  print(setVariationIndex)
~}

Running this program, I observe the following prints stepping through 3 days in the playground:

# Day 1
1
1  // <- expect 2!

# Day 2
2
1  // <- expect 3!

# Day 3
3
1 // <- Not sure if this is expected, is setVariationIndex automatically modded?

Variables impacted

I tested setVariationIndex and reps[1]. Both had issues. state variables appeared to not be impacted.

Workaround

Instead of using the add assignment operator, explicit add and assignment appears to work:

Squat / 3x5 / 3x3 / 3x1 / progress: custom() {~
  print(setVariationIndex)
  setVariationIndex = setVariationIndex + 1
  print(setVariationIndex)
~}

I just discovered liftosaur and I think it's pretty amazing! I'm happy to take a look at this issue later in the week when I get the repo setup locally. Depending on the difficulty of the fix, it might be better to just throw a descriptive warning if a user attempts to use += with non-state variables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions