ttscoff / bunch

Documentation repository for Bunch.app
https://bunchapp.co
116 stars 5 forks source link

Variables value changes in condition - bug or intentional? #316

Open stracker-phil opened 10 months ago

stracker-phil commented 10 months ago

I pass a variable to a snippet. The snippet uses the variable inside a condition, but in side that condition, the variable value is different from outside the condition.

Sample code:

---
title: Condition test
---

<<#SingleWindow
- app_name=Messages

<<#SingleWindow
- app_name=Slack

<<#SingleWindow
- app_name=Mail

___
---[SingleWindow]

(log Start: ${app_name})

if app_name

    (log Processing: ${app_name})
    ${app_name}
    - XX

    @${app_name}

    (pause 1)

end

(log Done: ${app_name})

Log-output in Console:

Start: Messages
Process: Mail  ## Variable changed from "Messages" to "Mail"
Done: Messages

Start: Slack
Process: Mail  ## Variable changed from "Slack" to "Mail"
Done: Slack

Start: Mail
Process: Mail
Done: Mail

As you can see, the log output inside the condition uses the value "Mail" for the app_name variable in all three cases, even though the log message before and after the condition displays the expected value.

Question: Is this expected? If yes, how can I "persists" a variable value inside a condition?

ttscoff commented 10 months ago

I'll need to dig back in and see if I can have it read the snippet fresh on each iteration, replacing the variable each time rather than permanently once and then not updating it on successive reads. So, in short, expected behavior, but not ideal behavior. Will dig back into this as I'm able.

-Brett

On 27 Jan 2024, at 11:23, Philipp Stracker wrote:

I pass a variable to a snippet. The snippet uses the variable inside a condition, but in side that condition, the variable value is different from outside the condition.

Sample code:

---
title: Condition test
---

<<#SingleWindow
- app_name=Messages

<<#SingleWindow
- app_name=Slack

<<#SingleWindow
- app_name=Mail

___
---[SingleWindow]

(log Start: ${app_name})

if app_name

    (log Processing: ${app_name})
    ${app_name}
    - XX

    @${app_name}

    (pause 1)

end

(log Done: ${app_name})

Log-output in Console:

Start: Messages
Process: Mail  ## Variable changed from "Messages" to "Mail"
Done: Messages

Start: Slack
Process: Mail  ## Variable changed from "Slack" to "Mail"
Done: Slack

Start: Mail
Process: Mail
Done: Mail

As you can see, the log output inside the condition uses the value "Mail" for the app_name variable in all three cases, even though the log message before and after the condition displays the expected value.

Question: Is this expected? If yes, how can I "persists" a variable value inside a condition?

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/bunch/issues/316 You are receiving this because you are subscribed to this thread.

Message ID: @.***>