Help, I'm having a weird problem in my game

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
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

Post by sheamkennedy »

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?
⊕ 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
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

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.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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.
⊕ 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
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

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.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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?
⊕ 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
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Well, not really. At every wait in one script there's the possibility for another script to run and change something, which have to add a check for. In that case zeroing out variables only helps if you make them global variables, probably not applicable if you have multiple NPCs.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

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.
Last edited by TMC on Mon May 04, 2015 5:53 am, edited 1 time in total.
User avatar
Soule X
Red Slime
Posts: 86
Joined: Wed Sep 19, 2012 4:18 pm
Location: Indianapolis

Post by Soule X »

It's probably too much to change now but the best thing to do when working with slices moving around is to put most if not all of it in one script. This makes sure you don't have multiple things affecting the same slice at the same time.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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
Post Reply