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!

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

 

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

 

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.

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

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

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.