den4 Posted March 8, 2017 Report Posted March 8, 2017 Can someone help please? I've been trying all afternoon to get the following simple script to work : - function Magsoff(off,val) if val = 0 then ipc.setbtncol(7, 255, 0, 0)--toggle to red else ipc.setbtncol(7, 224, 224, 224)--toggle to grey end end event.offsetmask(0x0892, 16, "UW", "Magsoff") Each time I try I get an error in the log Quote Battery toggle.lua:157: 'then' expected near '=' There is a "then" near to the "=" sign, so what am I doing wrong? I haven't got much hair left to tear out these days!
den4 Posted March 9, 2017 Author Report Posted March 9, 2017 Mario, thank you for that it has removed the error message now. Unfortunately it still doesn't do what I want it to do. It sets the button colour to red regardless of the value in the offset. Seems my logic is wrong somewhere as well! Den
Pete Dowson Posted March 9, 2017 Report Posted March 9, 2017 10 minutes ago, den4 said: Unfortunately it still doesn't do what I want it to do. It sets the button colour to red regardless of the value in the offset. Seems my logic is wrong somewhere as well! Two things: 1. It won't work with buttons set as Toggle buttons in the ButtonScreen definition. 2. Offset 0892 with never have the '16' bit set, as it only has the starter switch positions 0-2 for jets, 0-4 for props. Therefore the value with a mask of 16 is always zero. Pete
den4 Posted March 9, 2017 Author Report Posted March 9, 2017 Thanks Pete It isn't a toggle, just a button. I'd seen that in the documentation. But I'd totally misunderstood the point about the 16 bit though, I thought that was there because it was a 16 bit offset.. Still got a lot to learn! I'll have another go tomorrow.
Pete Dowson Posted March 9, 2017 Report Posted March 9, 2017 1 minute ago, den4 said: But I'd totally misunderstood the point about the 16 bit though, I thought that was there because it was a 16 bit offset.. No, the fact that it is 16 bit is in the "UW" parameter which means "Unsigned Word" (WORD = 16 bits). Since the event.offsetmask function is checking whether specified bits in the value have changed, it obviously needs those bits provided else it doesn't know what to test. When just reading a value you use event.offset. That will be triggered on any change in the offset. Pete
den4 Posted March 11, 2017 Author Report Posted March 11, 2017 Thanks both for your help, now working correctly.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now