Help, I'm having a weird problem in my game
Moderators: marionline, SDHawk
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Help, I'm having a weird problem in my game
I just noticed this weird problem in my game. In the game I have guards which walk around and shoot you if you are in their line of sight. The lasers they shoot are coded to originate from the NPC, this seems to always work. But occasionally when I face certain directions with my hero while they are shooting it seems that a second laser will be shot originating from the hero.
For example:
-guard sees me and begins to chase
-guard shoots eastward
-I am facing southward and a second laser shoots northward from my origin
It's very puzzling, I don't know what causes this. At first I thought I'd check through my code for "set parent" to make sure I didn't accidentally parent a laser to the hero instead of to the NPC. I've searched pretty well and can't find anything like that. I also thought I may narrow my search by looking at codes which specify the hero direction as south, still nothing seems out of place.
Does anyone have a test method I might use to solve this?
For example:
-guard sees me and begins to chase
-guard shoots eastward
-I am facing southward and a second laser shoots northward from my origin
It's very puzzling, I don't know what causes this. At first I thought I'd check through my code for "set parent" to make sure I didn't accidentally parent a laser to the hero instead of to the NPC. I've searched pretty well and can't find anything like that. I also thought I may narrow my search by looking at codes which specify the hero direction as south, still nothing seems out of place.
Does anyone have a test method I might use to solve 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
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
When a second laser appears, quickly press F8 and then view the slice tree. You can browse throug h the list of slices until you find the second laser, and you will be able to see what the second laser is actually parented to.
If that does not shed any light on the situation, you may need to post some scripts here.
If that does not shed any light on the situation, you may need to post some scripts here.
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
I figured it out, kind of...
Thanks to the slice tree I narrowed the script down to about 1000 lines of code in which the error may be occurring. The slice being produced was actually a Laser from an NPC who I had already destroyed. I had conditions to make sure that NPCs shooting script could not carry out unless the NPC was alive. I looked very hard for anything out of place in the code and attempted many minor changes. I didn't end up finding out what was wrong but after creating a redundancy which checks if NPC is alive within each shooting script I was able to eliminate the problem. I guess the added redundancy is solving the problem by double checking if NPC is alive, in the case of wherever the scripting is wrong it at least gets checked once. This is probably a messy way to code things but I've spent over 5 hours looking for the problem so it's as much as I'm willing to do now.
Maybe I'll post a video or gifs of my game soon to show off all the new and cool stuff at work.
Thanks to the slice tree I narrowed the script down to about 1000 lines of code in which the error may be occurring. The slice being produced was actually a Laser from an NPC who I had already destroyed. I had conditions to make sure that NPCs shooting script could not carry out unless the NPC was alive. I looked very hard for anything out of place in the code and attempted many minor changes. I didn't end up finding out what was wrong but after creating a redundancy which checks if NPC is alive within each shooting script I was able to eliminate the problem. I guess the added redundancy is solving the problem by double checking if NPC is alive, in the case of wherever the scripting is wrong it at least gets checked once. This is probably a messy way to code things but I've spent over 5 hours looking for the problem so it's as much as I'm willing to do now.
Maybe I'll post a video or gifs of my game soon to show off all the new and cool stuff at work.
⊕ 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
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Sounds like you might have multiple scripts running at the same time, so one starts and then another deletes the NPC? Or it could be another case of storing an NPC or slice reference in a variable and then deleting that NPC/slice without zeroing the variable holding the reference. NPC references and slice handles need exactly the same handling of invalidated references.
Last edited by TMC on Sun May 03, 2015 1:42 pm, edited 1 time in total.
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
It would likely be from multiple scripts running. I've made sure that everywhere in my code that frees a slice has line that sets that variable to zero in the following line.
So if it is multiple scripts running then is there a good way to solve this?
So if it is multiple scripts running then is there a good way to solve 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
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Actually my script does use global variables for zeroing freed slices and each of my enemies is represented by a separate unique NPC.
⊕ 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
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
In that case the difference between the right way and the other way of fixing it is unfortunately just to think carefully about where you need to add checks rather than adding them everywhere and hoping.
It's an easier version of multithreaded programming. Multithreaded programming is too hard for most programmers.
It's an easier version of multithreaded programming. Multithreaded programming is too hard for most programmers.
Last edited by TMC on Mon May 04, 2015 5:53 am, edited 1 time in total.
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
I would, only it's difficult with the way my games scripted. For example I need a script which shoots bullets from a player, then one which checks if that bullet collides with anything that can be killed and destroys the slice if necessary, then a timer that destroys the bullet if it's been on screen for more than a few seconds. Not to mention more complexed things than bullets, like my boomerang which requires a timer to change the direction of the boomerang after so much time has elapsed so it can appear to return to the player. The codes just getting too tough for me to handle in a single script, thus I've been combining many small simple scripts to accomplish big tasks. Also there's so much going on at any given time that I need multiple timers running simultaneously to carry them out. I'm trying to limit the amount of timers by making each map area only have a small handful of enemies. So far I have 20 timers running at most and no lag is noticed in gameplay which is good. I just hope as I progress I don't run in to to many issues with timers being triggered and the order they're carried out.
⊕ 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
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases