Jump to content
The simFlight Network Forums

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

 

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.