Jump to content
The simFlight Network Forums

setbits not working ?

Recommended Posts


i have this little function in a LUA Script to check/set the DoorSTate.

function DoorState()
    ipc.display("Doors", 3)
	ipc.setbitsUB(0x5302, 0)
    ipc.setbitsUB(0x5302, 1)

as you can see, i have testet if this script-function is called, and it is.

But the Offset is not set after the function is called.

Have you any idea why ?



Link to comment
Share on other sites



i dont know why it is not working:

function DoorState()
	local flag = 0
	--if doorflag0 == 1 then flag = flag + 1 end
	--if doorflag1 == 1 then flag = flag + 2 end
	--if doorflag2 == 1 then flag = flag + 4 end
	--if doorflag3 == 1 then flag = flag + 8 end
	--if doorflag4 == 1 then flag = flag + 16 end
	--if doorflag5 == 1 then flag = flag + 32 end
	--if doorflag6 == 1 then flag = flag + 64 end
	if doorflag0 == 1 then ipc.setbitsUB(0x5400, 1) end
	if doorflag1 == 1 then ipc.setbitsUB(0x5400, 2) end
	if doorflag2 == 1 then ipc.setbitsUB(0x5400, 3) end
	if doorflag3 == 1 then ipc.setbitsUB(0x5400, 4) end
	if doorflag4 == 1 then ipc.setbitsUB(0x5400, 5) end
	if doorflag5 == 1 then ipc.setbitsUB(0x5400, 6) end
	if doorflag6 == 1 then ipc.setbitsUB(0x5400, 7) end
	--ipc.display("DoorState " ..flag, 3)
	ipc.writeUB(0x5400, flag)

The ipc.setbits is not working.

The version with the "--" is working fine. I know it is doing the same, but it would be nice to know why the setbits is not working?


Link to comment
Share on other sites

If you want the byte in 5400 to contain a different integer depending on those doorflags then you should use "ipc.writeUB". Your code using "ipc.setbitsUB" will OR bits in on each use. For instance, if all 7 doorflags are set the result in 5400 with your code will just be '7'.

It looks really as if you want a different bit to be set in 5400 for each doorflag. In that case the values should be 1, 2, 4, 8, 16, 32 and 64.

Just remember: "setbits" means set the bits in the supplied value, OR'ing them into whatever is there. "clearbits" does trhe reverse, removing those bits (i.e. changing them to zero).  This method can set and clear mutiple bits in one instruction. You seem to be thinkning that the functions use bit numbers (0-7) which it does not.




Link to comment
Share on other sites

17 hours ago, mroschk said:

but it works and i dont need to OR the bits.


ipc.setbitsUB(0x5400, 1) 

is not setting bit 1 to 1


ipc.setbitsUB(0x5400, 2)

is not setting bit 2 to 1.


Sorry, it appears you still do not understand!  Value 1 is bit 0 and value 2 is bit 1. The values of the bits are as i said:

bit   value

0     1
1     2
2     4
3     8
4     16
5      32
6      64
7      128

The setbits and clrbits functions use the values, not the bit numbers, because they are designed to allow multiple bits to be set or cleared.



Link to comment
Share on other sites

Make bit 5 to 1 (SET) --> ipc.setbitsUB(0x5400, 32) 
Make bit 5 to 0 (CLEAR) --> ipc.clearbitsUB(0x5400, 32)

Setting or clearing multiple bits, add them up..
Make bits 1,5 & 7 to 1 (SET) --> ipc.setbitsUB(0x5400, 162) < 2 + 32 + 128 >
Make bits 1,5 & 7 to 0 (CLEAR) -->  ipc.clearbitsUB(0x5400, 162)



Link to comment
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
  • 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.