I'm making a game where the player can walk around using the arrow keys, and I want them to be able to walk into buildings. So I want the background to change when they step in front of the door to enter the building
Offline
This script will also allow the player to exit the building.
For the player:
For the Stage:whenclicked
foreveriftouchingdoor ▼?ifbuilding=outsidesetbuilding ▼toinsideifbuilding=insidesetbuilding ▼tooutside
I hope that's clear.whenclicked
foreverifbuilding=outsideswitch to backgroundoutside ▼ifbuilding=insideswitch to backgroundinside ▼
Last edited by PhirripSyrrip (2012-07-22 08:27:17)
Offline
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:For the Stage:whenclicked
foreveriftouchingdoor ▼?ifbuilding=outsidesetbuilding ▼toinsideifbuilding=insidesetbuilding ▼tooutsideI hope that's clear.whenclicked
foreverswitch to backgroundbuilding
Simpler
Offline
Prestige wrote:
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:For the Stage:whenclicked
forever iftouchingdoor ▼?ifbuilding=outsidesetbuilding ▼toinsideelsesetbuilding ▼tooutsideI hope that's clear.whenclicked
foreverswitch to backgroundbuildingSimpler
![]()
even more simple
when it touches the door and the backround changes, be sure to make it go to the correct position.
Offline
thebriculator wrote:
Prestige wrote:
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:For the Stage:whenclicked
forever iftouchingdoor ▼?ifbuilding=0setbuilding ▼to1elsesetbuilding ▼to0I hope that's clear.whenclicked
foreverswitch to backgroundbuildingSimpler
![]()
even more simple
![]()
when it touches the door and the backround changes, be sure to make it go to the correct position.
You guys are missing something: The stage treats the reporter as a number, so even if you name your costume that, it doesn't matter. Fixed.
Offline
berberberber wrote:
thebriculator wrote:
Prestige wrote:
Simpler![]()
even more simple
![]()
when it touches the door and the backround changes, be sure to make it go to the correct position.You guys are missing something: The stage treats the reporter as a number, so even if you name your costume that, it doesn't matter. Fixed.
![]()
For the purposes of the thread, and for simplicity and clarity in the project, I think mine will cause the least confusion.
Offline
It WILL work it it's a word, I just tried it.
but with numbers, it could be even more simple:
whenclicked
setbuilding ▼to0forever iftouchingdoor ▼?setbuilding ▼to1-buildingwhenclicked
foreverswitch to costumebuilding
Offline
thebriculator wrote:
It WILL work it it's a word, I just tried it.
but with numbers, it could be even more simple:whenclicked
setbuilding ▼to0forever iftouchingdoor ▼?setbuilding ▼to1-buildingwhenclicked
foreverswitch to costumebuilding
Costume numbering in scratch begins at 1, so, though your script could be applied, it is counter intuitive, so you should set "building" to 1 originally and replace "1-building" with "(3)-(building)"
The (potential) problem with all the scripts above is that, if you're touching the door for too long. If this is a problem, use this:
Of course, if there are only two costumes, it is even easier:whenclicked
setbuildiing ▼to1forever iftouchingdoor ▼?setbuilding ▼to3-buildingwait untilnottouchingdoor ▼?whenclicked
foreverswitch to costumebuilding
whenclicked
forever iftouchingdoor ▼?broadcastchange ▼wait untilnottouchingdoor ▼?When I Receivechange ▼next costume
Offline
thebriculator wrote:
Prestige wrote:
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:For the Stage:whenclicked
forever iftouchingdoor ▼?ifbuilding=outsidesetbuilding ▼toinsideelsesetbuilding ▼tooutsideI hope that's clear.whenclicked
foreverswitch to backgroundbuildingSimpler
![]()
even more simple
![]()
when it touches the door and the backround changes, be sure to make it go to the correct position.
Can you maybe make this and upload it? I don't understand
Offline
We've been assuming that you're storing the interior of the building as a costume in the background, and that the door itself is a sprite. Basically, whenever the user touches the door it changes the costume that the background is currently in. A more universal script (just realized you probably have more than one building) would be this:
And for the stage:whenclicked
foreverwhatever your current movement script isiftouchingdoor1 ▼?broadcastenter building 1 ▼and waitgo to x:starting x position for building 1y:starting y position for building 1iftouchingdoor2 ▼?broadcastenter building 2 ▼and waitgo to x:starting x position for building 2y:starting y position for building 2etc.
when I receiveenter building 1 ▼switch to costumebuilding 1 ▼when I receiveenter building 2 ▼switch to costumebuilding 2 ▼
Offline