How to execute a function only once during a "repeat until" loop?

Hi,
I was wondering how I could send a single message during a repeat until loop. As of right now, I tried using this method but haven’t been successful.

function init(self)
   messageSending = false
end

local function xyz()
    repeat
        if a < b and messageSending == false then
            msg.post(".", "abc")
            a = a + 1
    else if a > b and messageSending == false then
            msg.post(".","bac")
            a = a-1
     end
until  a == b
end

You never set it to true. That’s why it doesn’t work.
And it should be self.messageSending :slight_smile:

2 Likes

Oh. That definitely seems like a problem. I don’t know why I didn’t brain hard enough. Also, is using self or local required for declaring all variables?

Also, when I included to (“self.” and the messageSending = true)there was an error in the console:

attempt to index global ‘self’ (a nil value)

I got this error a bunch of times when I tried to set a self.something variable to a different value so I tried to not use self.

Hey @klu2022

You need to make sure you pass “self” into your function for it to be accessible. Change to

Local function xyz(self)
And when you call the function, call xyz(self)

1 Like