Jump to content

ACS: Floor raises indefinitely on second trigger


Recommended Posts

I have this script to make a crushing floor move up 32 units each time a switch is hit:

script 1 (int rfTag)
{
	int currentHeight = GetSectorFloorZ(rfTag, 0, 0);
	int targetHeight = currentHeight +32;

	Delay(35);
	Floor_MoveToValueAndCrush(rfTag, 16, targetHeight, 200, 3);
}

It works fine the first time, but on the second press it just goes up into the ceiling indefinitely. I can't for the life of me figure out why this is happening.

Even using a regular Floor_MoveToValue has the same issue. Stranger still, if I treat targetHeight in the action as a negative value, the floor goes down the first time, and infinitely up the second time as before.

What is going on?

Edited by den killen

Share this post


Link to post

GetSectorFloorZ returns fixed number, which is 65536 times bigger than the integer value you probably expect, so if the sector floor is at height 32, then the "currentHeight" variable will be 2097152 -> target height will be at 2097184, which might look like it goes indefinitely.

 

https://zdoom.org/wiki/GetSectorFloorZ

https://zdoom.org/wiki/Fixed_point_number

Edited by jaeden

Share this post


Link to post
41 minutes ago, jaeden said:

GetSectorFloorZ returns fixed number, which is 65536 times bigger than the integer value you probably expect, so if the sector floor is at height 32, then the "currentHeight" variable will be 2097152 -> target height will be at 2097184, which might look like it goes indefinitely.

 

https://zdoom.org/wiki/GetSectorFloorZ

https://zdoom.org/wiki/Fixed_point_number

 

What is the reason for it doing that without converting to an integer?

Would I just need to divide every use of it by 65536 (it finally works, but seems superfluous)?

Edited by den killen

Share this post


Link to post
8 hours ago, den killen said:

Would I just need to divide every use of it by 65536 (it finally works, but seems superfluous)? 

Use the bit shift operator, >> 16. Here's a previous explanation on fixed point numbers:

 

 

Share this post


Link to post
13 hours ago, Edward850 said:

Use the bit shift operator, >> 16.

Gotcha. I was originally using a constant but this is much cleaner. Thanks!

Edited by den killen

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...