Button not appearing every time it should [SOLVED]

For some reason I can’t get the sleep button to appear when close to any house.
If I create one house, it works, but if I create another one, it will only appear near the newly created one, not both which I want it to appear when close to any house

If anyone could show me how to do it, that would be very helpful

10 Likes

How are you doing it currently?

5 Likes

When an object clones, the clone is constantly checking if self is close to your character. If it is, set a variable to 1 making the button set it’s invisibility to 0

4 Likes

Do you have any variables set by the clone to set the position of the button? Position it near the house and have the house check if it is closest to the button would be the easiest. Make sure that only houses close enough to the character check how close they are to the button.

3 Likes

The button is supposed to appear when the character is close to a house

3 Likes

Are you sure that every house is checking? Have you tried making 3 and testing all of those?

3 Likes

If I create one, it works, but if I create the second one, it will only appear for the second one, not the first.
Same goes with how ever many you create, it only appears for the newest created clone

3 Likes

Then it sounds like only the last clone is checking. Try to figure out why.

4 Likes

The clone also checks if (self)Clone Index > 1

3 Likes

That shouldn’t have the effect that you’re seeing. How does it check? Is it in a loop or a conditional when?


Could a leader move this discussion (Starting here) to a new topic in #debug-my-code?

4 Likes

When game is playing

If (house is close to character)

If (self)Clone Index > 1
Set (variable) to 1

Else
Set (variable) to 0

1 Like

Where is the check for clone index?

2 Likes

(Moved to new topic)

2 Likes

Cøuld yøu shøw us a link tø the prøject?

I edited it in

2 Likes

The issue is

This sets it to 0 if the house is not near the player. The reason this doesn’t affect the most recent house is because of the order that the code is run. All the previous objects will run it, each setting it to 0 in the order that they were created in. This means that the last object sets it to 1 and nothing after it returns it to 0. Find a way to only set it to 0 if no houses are close to the player.

2 Likes

Thanks for the help. I’ll be spending a few days trying to figure out how to do that

1 Like

One idea I had was to calculate the minimum (smallest) distance to a house each frame. You could start by first setting a variable for minimum distance to some high value (such as 014014014, though anything further than where you want the button to appear works) and then having each house (In the same frame) set it to minimum(current value, self distance). If the minimum distance is close enough to show the button, the button should be shown. Otherwise it should be hidden. This could possibly replace what you already have.

2 Likes

A way to do this would be to have two separate rules (Assuming you’re using a recent player version).
One

When ((self.clone index) = (1))
to set the variable to a large value.

Also one

When (Game is playing)
to calculate the current distance then set the variable to the smallest between its current value and the clone’s distance. Only use set variable blocks for this (or put one block per rule) to make sure it happens every frame.
2 Likes

I don’t understand

1 Like