I got no ideas on this one. My only thought would be that maybe it's constantly setting his speed and not letting him walk, or that maybe he's midstep or something and getting desynched from the map somehow. Maybe set up a second tag, or something to make sure that the speed is only changed once, and not once every tick while Levers > 6. Maybe once it's only happening once, add a "waitfornpc" thing to make sure it's aligned with the grid before you switch from 2 to 4.
Otherwise, I don't see anything in the scripts presented that would cause it to do that. Weird problem, but I'd have to see more to accurately diagnose.
Alright I'm back from vacation and still struggling a bit. I wrote up what I think to be a simple collision test to see if my slice collision works. It looks like so:
This script is called in my autorun script. When I try to run this in game it gives the error:
Invalid slice handle 261
These slices do exist in my slice collections, so why the error? They have also been exported to an HSI included in my script to clarify things.
EDIT:
I have just updated my script to this. It got rid of the error but still no collision is recognized since the NPC is not being destroyed... Any ideas why? I'm positive these slices are making contact.
EDIT #2:
After further realizing that Gizmog and Urkel were discussing something like this earlier I have further revised my code to use handles rather than slices as I made this similar mistake. Still though I am having trouble with getting the code to work. Here's the latest revision of the code:
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Code:
script, checkCollisions, begin
if (SliceCollide (sli:Hitbox1, sli: Bullet1)) then (
DestroyNPC (0)
)
end
script, checkCollisions, begin
if (SliceCollide (sli:Hitbox1, sli: Bullet1)) then (
DestroyNPC (0)
)
end
This script is called in my autorun script. When I try to run this in game it gives the error:
Invalid slice handle 261
These slices do exist in my slice collections, so why the error? They have also been exported to an HSI included in my script to clarify things.
EDIT:
I have just updated my script to this. It got rid of the error but still no collision is recognized since the NPC is not being destroyed... Any ideas why? I'm positive these slices are making contact.
Code:
script, checkCollisions, begin
if (slice is valid(sli:Hitbox1) && slice is valid(sli:Bullet1)) then(
if (slice collide (sli:Hitbox1, sli:Bullet1)) then(
free slice (sli:Hitbox1)
free slice (sli:Bullet1)
DestroyNPC (0)
)
)
end
if (slice is valid(sli:Hitbox1) && slice is valid(sli:Bullet1)) then(
if (slice collide (sli:Hitbox1, sli:Bullet1)) then(
free slice (sli:Hitbox1)
free slice (sli:Bullet1)
DestroyNPC (0)
)
)
end
EDIT #2:
After further realizing that Gizmog and Urkel were discussing something like this earlier I have further revised my code to use handles rather than slices as I made this similar mistake. Still though I am having trouble with getting the code to work. Here's the latest revision of the code:
Code:
script, checkCollisions, begin
if (slice is valid(sli:Hitbox1) && slice is valid(sli:Bullet1)) then(
if (slice collide (LookUpSlice (sli:Hitbox1), LookUpSlice (sli:Bullet1)) == true) then(
destroy NPC (0)
play sound (4, false, true)
)
)
end
if (slice is valid(sli:Hitbox1) && slice is valid(sli:Bullet1)) then(
if (slice collide (LookUpSlice (sli:Hitbox1), LookUpSlice (sli:Bullet1)) == true) then(
destroy NPC (0)
play sound (4, false, true)
)
)
end
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
I had wanted to do a bit more polish on this before I showed it to you, but I got all mixed up with reviews and gettin curious about different stuff and lost sight of the original goal. I made this as an example of the kind of gameplay I think you guys are goin' for. You're free to learn from it, modify it, steal it, whatever the hell you want. If that kinda thing isn't your style, I understand 100% and am willing to keep answering questions and trying to figure this out for as long as it takes.
I'm kinda stumped on this current issue, my only theory is that somehow the slices aren't actually being created, or that somehow they don't think they're colliding. Have you tried doing something silly like vibrating the slices or cycling its colors wildly to see if you're referring to the right things?
I'm kinda stumped on this current issue, my only theory is that somehow the slices aren't actually being created, or that somehow they don't think they're colliding. Have you tried doing something silly like vibrating the slices or cycling its colors wildly to see if you're referring to the right things?
This is the code that I eventually stumbled upon after lots of questions and trial and error. I'm not sure if it will be of any help or not, but I figured it couldn't hurt. Keep in mind this code is VERY sloppy, and possibly not formatted well. I tend to stop fiddling with things as soon as I get something to work.
The first is my hit detection script (equivalent to your CheckCollisions) It looks quite similar to your existing code, so this may not be of any help.
Below is a sample of my map autorun script for the rooms in which shooting will occur. I was wondering if your problem was related to not having your CheckCollisions script inside a While Loop. This is something I was struggling with for a while. I would shoot and the bullet would go through the baddy with nothing happening. (In this game the player must hit 6 levers to win, hence the while conditional)
Again, I don;t know if any of this will be of any use at all. If it looks screwy to you, just ignore it
I am admittedly not very good with this stuff
I'll also just add that my game consists of several one-screen rooms. Shooting only occurs in the 6 rooms containing a monster, and only after the player picks up a gun powerup, giving them only one shot.
I attempted having the gun weapon available in every room, with 4 shots, but i ran into problems with invalid slice handles, and eventually gave up and made the shooting system VERY primitive. So These scripts may not help at all for what you're attempting.
Best of luck!!
EDIT: Oh, and I've been using the stable version of OHR, but if you're using a newer nightly build, you can throw in some slice dissolve commands to make the enemy death look really rad!
The first is my hit detection script (equivalent to your CheckCollisions) It looks quite similar to your existing code, so this may not be of any help.
Code:
plotscript, hitdetect,begin
if (
(slice is valid (bullet)==true) &&
(slice is valid (2)==true)
)
then
(
if
(slice collide (bullet,2) ==true)
then (
increment (score, 1750)
(suspend NPCs)
(stop slice (2))
(free slice (bullet))
(play sound (23,false,false))
(Wait (20))
(set tag (28, off))
(resume NPCs)
(exit script)
)
)
end
plotscript, hitdetect,begin
if (
(slice is valid (bullet)==true) &&
(slice is valid (2)==true)
)
then
(
if
(slice collide (bullet,2) ==true)
then (
increment (score, 1750)
(suspend NPCs)
(stop slice (2))
(free slice (bullet))
(play sound (23,false,false))
(Wait (20))
(set tag (28, off))
(resume NPCs)
(exit script)
)
)
end
Below is a sample of my map autorun script for the rooms in which shooting will occur. I was wondering if your problem was related to not having your CheckCollisions script inside a While Loop. This is something I was struggling with for a while. I would shoot and the bullet would go through the baddy with nothing happening. (In this game the player must hit 6 levers to win, hence the while conditional)
Code:
while (lever<6>>0)
then(
(shootabullet2)
)
while (lever<6>>0)
then(
(shootabullet2)
)
Again, I don;t know if any of this will be of any use at all. If it looks screwy to you, just ignore it
I am admittedly not very good with this stuff
I'll also just add that my game consists of several one-screen rooms. Shooting only occurs in the 6 rooms containing a monster, and only after the player picks up a gun powerup, giving them only one shot.
I attempted having the gun weapon available in every room, with 4 shots, but i ran into problems with invalid slice handles, and eventually gave up and made the shooting system VERY primitive. So These scripts may not help at all for what you're attempting.
Best of luck!!
EDIT: Oh, and I've been using the stable version of OHR, but if you're using a newer nightly build, you can throw in some slice dissolve commands to make the enemy death look really rad!
@Urkel:
Thanks this may help. In your code where is "bullet" and "2" defined within your code or within your game engine?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Thanks this may help. In your code where is "bullet" and "2" defined within your code or within your game engine?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Bullet is defined in my bullet shooting script. 2 is the slice handle of the monster the player will shoot at. I had trouble with variables, so I eventually found out that "2" was the slice handle I needed to use for the baddy in my collision script.
... sorry if that doesn't make much sense. I believe the script I'm using below is actually a bastardized version of one you may have posted in another thread. I know I stole it from somewhere
... sorry if that doesn't make much sense. I believe the script I'm using below is actually a bastardized version of one you may have posted in another thread. I know I stole it from somewhere
Code:
plotscript, shootabullet2, begin
variable(sl, isshooting)
while (keyval (key:space)>>0)
do
(
if(hero direction (me)== right) then(
bullet := create rect (3, 3, 2)
put slice (bullet, hero pixel x, hero pixel y)
set slice velocity x (bullet, 15, 30)
set slice velocity y (bullet, 0, 30)
(play sound (21,false,false))
delete item (item:shell, 1) #ammo
exit script
) else
if(hero direction (me)== left) then(
bullet := create rect (3, 3, 2)
put slice (bullet, hero pixel x, hero pixel y)
set slice velocity x (bullet, -15, 30)
set slice velocity y (bullet, 0, 30)
(play sound (21,false,false))
delete item (item:shell, 1)
exit script
) else
#etc...
variable(sl, isshooting)
while (keyval (key:space)>>0)
do
(
if(hero direction (me)== right) then(
bullet := create rect (3, 3, 2)
put slice (bullet, hero pixel x, hero pixel y)
set slice velocity x (bullet, 15, 30)
set slice velocity y (bullet, 0, 30)
(play sound (21,false,false))
delete item (item:shell, 1) #ammo
exit script
) else
if(hero direction (me)== left) then(
bullet := create rect (3, 3, 2)
put slice (bullet, hero pixel x, hero pixel y)
set slice velocity x (bullet, -15, 30)
set slice velocity y (bullet, 0, 30)
(play sound (21,false,false))
delete item (item:shell, 1)
exit script
) else
#etc...
Back! No! Never use the number as a slice handle! Always store your slice handles in variables no matter what.
Just because it is 2 right now, don't assume it will always be 2. Any tiny little change could unexpectedly change it to 3 or 5 or 467
I haven't read the whole thread yet, but I'll come back later and read it and see if I can provide some help
Just because it is 2 right now, don't assume it will always be 2. Any tiny little change could unexpectedly change it to 3 or 5 or 467
I haven't read the whole thread yet, but I'll come back later and read it and see if I can provide some help
I think most of the problem is in referring to the slices. So what I think you oughta do is take a step back and make sure you're getting that part right first. Using a number like "2" to refer to a slice is really dangerous because a slice's handle is like...
Imagine you've got an empty neighborhood, and as people move in, they take the first house that's available. Now suppose you've got 5 guys, and every night they move in, every morning they move out and go to work. They work their shifts such that they always arrive and leave in the same order, so their order never changes.
The guy who usually is in House 2 decides to subscribe to a magazine, and has it delivered to House 2. That's all perfectly good until some other guy moves in unexpectedly, or someone comes home from work too early, or Magazine Guy has to stay late or something. The magazine is still going to House 2, but the guy who wants it isn't there any more.
That's basically how Slice Handles work. When you create a slice, the game assigns the first unused number and when you free a slice the game returns that number to the pool of possible handles. So blindly saying "2" is dangerous and could have disastrous consequences if you change the way your script works. I remember suggesting it, but only as a way to understand that ultimately, slice handles are just numbers.
Like James says, the best way to do it is with variables (preferably global, as you're clearly going to be needing to refer to the same slice across multiple scripts in this case).
Here's the kind of silly example I made when I was first figuring slices out, it creates two rectangle slices and then randomly positions one until they collide, at which point the game is over. It doesn't use/need slice look up codes or collections at all because it creates the slices in the script
and records the handles to the globals at the time of their creation.
I think right now you've got so much different stuff that can go wrong, in terms of referring to the slices and creating them with your button pushes and checking the collisions and everything that it's getting really hard for you to figure out why things are doin' what they're doin', and you're starting to get into superstitious stuff. Don't be afraid to go back to basics a little bit and just screw around with stuff in a context free and worry free environment before trying to apply it to your actual game.
EDIT: As a general complaint, and I forget if I'm repeating myself or not, if I am I'm sorry, I always got really confused when I read the wiki and saw stuff like
because I'd never Set a Variable's value that way before. I always used Increment, Decrement, or SetVariable. It made me think you had to set up the variable as like a... password or a ritual or something, and that sl := LoadASprite was some kinda required magic like how $1="AString" works.
Imagine you've got an empty neighborhood, and as people move in, they take the first house that's available. Now suppose you've got 5 guys, and every night they move in, every morning they move out and go to work. They work their shifts such that they always arrive and leave in the same order, so their order never changes.
The guy who usually is in House 2 decides to subscribe to a magazine, and has it delivered to House 2. That's all perfectly good until some other guy moves in unexpectedly, or someone comes home from work too early, or Magazine Guy has to stay late or something. The magazine is still going to House 2, but the guy who wants it isn't there any more.
That's basically how Slice Handles work. When you create a slice, the game assigns the first unused number and when you free a slice the game returns that number to the pool of possible handles. So blindly saying "2" is dangerous and could have disastrous consequences if you change the way your script works. I remember suggesting it, but only as a way to understand that ultimately, slice handles are just numbers.
Like James says, the best way to do it is with variables (preferably global, as you're clearly going to be needing to refer to the same slice across multiple scripts in this case).
Here's the kind of silly example I made when I was first figuring slices out, it creates two rectangle slices and then randomly positions one until they collide, at which point the game is over. It doesn't use/need slice look up codes or collections at all because it creates the slices in the script
and records the handles to the globals at the time of their creation.
Code:
include, plotscr.hsd
GlobalVariable (1,SquareOne)
GlobalVariable (2,SquareTwo)
plotscript,SquareTest,begin
#Creates a 20x20 square and records its handle in the
#global variable SquareOne
SetVariable ( SquareOne,CreateRect (20,20) )
#Ditto for SquareTwo, only it's shorter to type it this way
SquareTwo := CreateRect (20,20)
#Centers the slice identified by the global variable
#Square Two
CenterSlice (SquareTwo)
#Repeats the commands in the do block every tick,
#indefinitely
while (true)
do (
#Puts Square one somewhere on the screen at random
putslice (SquareOne,Random (0,300),Random (0,180))
#If the two Squares are colliding...
if (SliceCollide (SquareOne,SquareTwo))
then (GameOver)
wait (1)
)
end
include, plotscr.hsd
GlobalVariable (1,SquareOne)
GlobalVariable (2,SquareTwo)
plotscript,SquareTest,begin
#Creates a 20x20 square and records its handle in the
#global variable SquareOne
SetVariable ( SquareOne,CreateRect (20,20) )
#Ditto for SquareTwo, only it's shorter to type it this way
SquareTwo := CreateRect (20,20)
#Centers the slice identified by the global variable
#Square Two
CenterSlice (SquareTwo)
#Repeats the commands in the do block every tick,
#indefinitely
while (true)
do (
#Puts Square one somewhere on the screen at random
putslice (SquareOne,Random (0,300),Random (0,180))
#If the two Squares are colliding...
if (SliceCollide (SquareOne,SquareTwo))
then (GameOver)
wait (1)
)
end
I think right now you've got so much different stuff that can go wrong, in terms of referring to the slices and creating them with your button pushes and checking the collisions and everything that it's getting really hard for you to figure out why things are doin' what they're doin', and you're starting to get into superstitious stuff. Don't be afraid to go back to basics a little bit and just screw around with stuff in a context free and worry free environment before trying to apply it to your actual game.
EDIT: As a general complaint, and I forget if I'm repeating myself or not, if I am I'm sorry, I always got really confused when I read the wiki and saw stuff like
Code:
variable(sl)
sl := load large enemy sprite(0)
variable(sl)
sl := load large enemy sprite(0)
because I'd never Set a Variable's value that way before. I always used Increment, Decrement, or SetVariable. It made me think you had to set up the variable as like a... password or a ritual or something, and that sl := LoadASprite was some kinda required magic like how $1="AString" works.
Indeed! My use of "2" as a slice handle was due to repeated errors, and my inability to figure out how to identify the slice handle otherwise. "2" was my monster, I know exactly what graphics I want to use for it, but I kept getting Invalid Slice handle errors when I would try to define it as a global variable. (most likely silly errors in my scripting)
I never learned how to achieve this, but the nature of my game is so simplistic (single rooms, a single enemy, a single bullet) that when I found that using "2" as a slice handle always worked, I cut my losses and just used it throughout.
I never learned how to achieve this, but the nature of my game is so simplistic (single rooms, a single enemy, a single bullet) that when I found that using "2" as a slice handle always worked, I cut my losses and just used it throughout.
No, I am really serious, you should not use 2, no matter how simple your script is.
When I say the number could change as a result of any tiny change, I am not just talking about changes to your script, I mean changes to other parts of your game, changes in future updates of the OHRRPGCE. Your game is incredibly fragile if you use the number 2 this way. I wish I could make a fatal plotscript compiler error when you try to do this.
You said you have a single enemy, and you need to get the slice handle for it, right? And that enemy is an NPC?
start with the NPC ID number. Lets just say it is NPC 0, you just need to use the "get npc slice" command
Just put that in every place where you are currently using "2" as a slice handle.
When I say the number could change as a result of any tiny change, I am not just talking about changes to your script, I mean changes to other parts of your game, changes in future updates of the OHRRPGCE. Your game is incredibly fragile if you use the number 2 this way. I wish I could make a fatal plotscript compiler error when you try to do this.
You said you have a single enemy, and you need to get the slice handle for it, right? And that enemy is an NPC?
start with the NPC ID number. Lets just say it is NPC 0, you just need to use the "get npc slice" command
Code:
get npc slice(0)
Just put that in every place where you are currently using "2" as a slice handle.
Alright here's my latest update. I have taken the advise to create a program independent from my game and have come up with a nice minimal script that allows the player to shoot bullets and see if they collide. The script is as follows:
This code almost works. When I play the game the SFX plays over and over again. If my code is in fact correct this must mean that the bullet and hitbox are already colliding, but this is not the case since I haven't even shot a bullet yet... So how can this be. I did some investigating in to the slice tree and notice that there are two things titled "walkabout_sprite_component" which are overlapping in the upper left corner, coordinates (0,0) of my screen. I suspect these may be the culprits
. So how do I work around this? As far as I understand from the plotscripting dictionary the function "slice collide" does not account for parents... Does this somehow mean my code is targeting the walkabout_sprite_components rather than the slices? Or is my problem something else.
At least the codes a lot simpler to work with now. I think we should be able to tackle this.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Code:
include, plotscr.hsd
include, scancode.hsi
include, gun.hsi
#GLOBALS
global variable (1, isShooting)
global variable (2, hitbox)
global variable (3, Bullet)
#NOTES:
#Lookup Slice - returns a "handle"
#Slice is Valid - Returns true if the given id is a valid slice handle.
# The main use of this command is to check whether a slice has been
# deleted, avoiding a script error.
#Slice Collide - Takes in handles, returns true or false, Parent/child
# relationships have nothing to do with this test.
#_____________________________________________
plotscript, Map Auto Run, begin
variable (collection)
collection := load slice collection(1)
#Guard 1
#Define and parent the hitbox
hitbox:= lookup slice(sli:Hitbox1, collection)
setparent (hitbox, GetNPCSlice (0))
#Position the hitbox
set slice edge x (hitbox, edge:top, 2)
set slice edge y (hitbox, edge:top, -2)
#While map is running perform this loop
While (current map == current map) do(
#This checks if projectile is colliding, then kills corresponding NPC
checkCollisions
wait(1)
)
end
#_____________________________________________
plotscript, On Keypress Handler, begin
variable (collection)
if(key is pressed(key:X)) then(
if(isShooting <> 1) then(
isShooting := 1
if(hero direction == right) then(
collection := load slice collection(0)
Bullet := lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, 20, 10)
set slice velocity y (Bullet, 0, 10)
isShooting := 1
wait for slice(Bullet) #WORKS
free slice(Bullet) #WORKS
isShooting := 0
exit script
)
if(hero direction == left) then(
collection := load slice collection(0)
Bullet:= lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, -20, 10)
set slice velocity y (Bullet, 0, 10)
wait for slice(Bullet)
free slice(Bullet)
isShooting := 0
exit script
)
if(hero direction == up) then(
collection := load slice collection(0)
Bullet:= lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, 0, 10)
set slice velocity y (Bullet, -20, 10)
wait for slice(Bullet)
free slice(Bullet)
isShooting := 0
exit script
)
if(hero direction == down) then(
collection := load slice collection(0)
Bullet:= lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, 0, 10)
set slice velocity y (Bullet, 20, 10)
wait for slice(Bullet)
free slice(Bullet)
isShooting := 0
exit script
)
isShooting := 0
)
)
end
#_____________________________________________
script, checkCollisions, begin
if ((slice is valid(sli:Bullet1) == true) && (slice is valid(sli: Hitbox1) == true)) then(
if (SliceCollide (sli:Bullet1, sli: Hitbox1)) then (
#destroy NPC (0)
play sound (1, false, true)
)
)
)
include, plotscr.hsd
include, scancode.hsi
include, gun.hsi
#GLOBALS
global variable (1, isShooting)
global variable (2, hitbox)
global variable (3, Bullet)
#NOTES:
#Lookup Slice - returns a "handle"
#Slice is Valid - Returns true if the given id is a valid slice handle.
# The main use of this command is to check whether a slice has been
# deleted, avoiding a script error.
#Slice Collide - Takes in handles, returns true or false, Parent/child
# relationships have nothing to do with this test.
#_____________________________________________
plotscript, Map Auto Run, begin
variable (collection)
collection := load slice collection(1)
#Guard 1
#Define and parent the hitbox
hitbox:= lookup slice(sli:Hitbox1, collection)
setparent (hitbox, GetNPCSlice (0))
#Position the hitbox
set slice edge x (hitbox, edge:top, 2)
set slice edge y (hitbox, edge:top, -2)
#While map is running perform this loop
While (current map == current map) do(
#This checks if projectile is colliding, then kills corresponding NPC
checkCollisions
wait(1)
)
end
#_____________________________________________
plotscript, On Keypress Handler, begin
variable (collection)
if(key is pressed(key:X)) then(
if(isShooting <> 1) then(
isShooting := 1
if(hero direction == right) then(
collection := load slice collection(0)
Bullet := lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, 20, 10)
set slice velocity y (Bullet, 0, 10)
isShooting := 1
wait for slice(Bullet) #WORKS
free slice(Bullet) #WORKS
isShooting := 0
exit script
)
if(hero direction == left) then(
collection := load slice collection(0)
Bullet:= lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, -20, 10)
set slice velocity y (Bullet, 0, 10)
wait for slice(Bullet)
free slice(Bullet)
isShooting := 0
exit script
)
if(hero direction == up) then(
collection := load slice collection(0)
Bullet:= lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, 0, 10)
set slice velocity y (Bullet, -20, 10)
wait for slice(Bullet)
free slice(Bullet)
isShooting := 0
exit script
)
if(hero direction == down) then(
collection := load slice collection(0)
Bullet:= lookup slice(sli:Bullet1, collection)
set parent(Bullet, get hero slice (0))
set slice velocity x (Bullet, 0, 10)
set slice velocity y (Bullet, 20, 10)
wait for slice(Bullet)
free slice(Bullet)
isShooting := 0
exit script
)
isShooting := 0
)
)
end
#_____________________________________________
script, checkCollisions, begin
if ((slice is valid(sli:Bullet1) == true) && (slice is valid(sli: Hitbox1) == true)) then(
if (SliceCollide (sli:Bullet1, sli: Hitbox1)) then (
#destroy NPC (0)
play sound (1, false, true)
)
)
)
This code almost works. When I play the game the SFX plays over and over again. If my code is in fact correct this must mean that the bullet and hitbox are already colliding, but this is not the case since I haven't even shot a bullet yet... So how can this be. I did some investigating in to the slice tree and notice that there are two things titled "walkabout_sprite_component" which are overlapping in the upper left corner, coordinates (0,0) of my screen. I suspect these may be the culprits
. So how do I work around this? As far as I understand from the plotscripting dictionary the function "slice collide" does not account for parents... Does this somehow mean my code is targeting the walkabout_sprite_components rather than the slices? Or is my problem something else.
At least the codes a lot simpler to work with now. I think we should be able to tackle this.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Urkelbot666 wrote:
I'm using the walktall scripts so the NPC is currently replaced with a Hero Battle sprite set. (1)
Ah, no worries. That can be adjusted for.
Code:
get npc slice(0)
The command above gets the NPC container slice, but since you are using walktall, you want the NPC sprite slice instead, since you converted it into a hero sprite that is of a bigger size.
Code:
lookup slice(sl:walkabout sprite component, get npc slice(0))
The command above gets the sprite component of the npc. Now that is pretty long, and inserting that everywhere in your script might make things hard to read. That is why putting it in a global variable an be helpful, but there is another option too.
Code:
script, get enemy handle, begin
exit returning(lookup slice(sl:walkabout sprite component, get npc slice(0)))
end
exit returning(lookup slice(sl:walkabout sprite component, get npc slice(0)))
end
This script gets the handle, and then returns it. That means you can write "get enemy handle" any place that needs the slice handle of the enemy sprite.
Code:
if
(slice collide (bullet, get enemy handle) ==true)
then (
if
(slice collide (bullet, get enemy handle) ==true)
then (
sheamkennedy wrote:
Alright here's my latest update. I have taken the advise to create a program independent from my game and have come up with a nice minimal script that allows the player to shoot bullets and see if they collide. The script is as follows:
The main problem here is that you are using slice lookup codes in commands that only work with slice handles.
All of the sli:Name constants like sli:Hitbox1 are lookup codes, and that means there are only three commands that should ever use them.
lookup slice
get slice lookup
set slice lookup
You can ignore get slice lookup and set slice lookup. Those are relatively advanced commands that you are not likely to need. For your purposes, "lookup slice" is the only command that should ever have sli:Hitbox1 as an argument.
Code:
script, checkCollisions, begin
if ((slice is valid(sli:Bullet1) == true) && (slice is valid(sli: Hitbox1) == true)) then(
if (SliceCollide (sli:Bullet1, sli: Hitbox1)) then (
#destroy NPC (0)
play sound (1, false, true)
)
)
)
script, checkCollisions, begin
if ((slice is valid(sli:Bullet1) == true) && (slice is valid(sli: Hitbox1) == true)) then(
if (SliceCollide (sli:Bullet1, sli: Hitbox1)) then (
#destroy NPC (0)
play sound (1, false, true)
)
)
)
The reason this script fails is because it is using slice lookup codes in places where slice handles are required. I wish I could make it show an error message when you try to do that, but it will have to wait until some of TMC's planned plotscripting improvements are implemented.
Here is how I would write that same script:
Code:
script, checkCollisions, begin
variable(b, h)
b := lookup slice(sli:Bullet1)
h := lookup slice(sli:Hitbox1)
if (b && h) then(
if (SliceCollide (b, h)) then(
#destroy NPC (0)
play sound (1, false, true)
)
)
)
script, checkCollisions, begin
variable(b, h)
b := lookup slice(sli:Bullet1)
h := lookup slice(sli:Hitbox1)
if (b && h) then(
if (SliceCollide (b, h)) then(
#destroy NPC (0)
play sound (1, false, true)
)
)
)
Notice that I am not bothering with "slice is valid". That is because "lookup slice" is doing an equivalent check internally. It will always return either a valid slice or "false"
Another minor issue I noticed in your script was this:
Code:
#While map is running perform this loop
While (current map == current map) do(
#While map is running perform this loop
While (current map == current map) do(
Because current map is always equal to current map, this is equivalent to writing:
Code:
#perform this loop forever
While (true) do(
#perform this loop forever
While (true) do(



