Help with Variables and some other stuff I might have forgotten

I’m trying to create an HP system for a game I’m making (wave based top down shooter ish typa thing I’m making cuz bored) and I’m having trouble with the communication of the HP variables

In essence I want to make variables that are linked between the clones of the enemy types that spawn to attack the player, the player’s projectiles that damage the clones, and/or any clones of the weapons the enemies use

Intended Result: Projectile charges, while charging enemies that touch it cannot be damaged (to prevent cheesing). Upon release, mobs hit by projectile will lose 1 hp (ranges from 1-5 per enemy type) and when HP reaches 0 the clone is removed from view and deleted, alone with any weapons they use

I’ve tried a bunch of different things but none of them work quite right in one way or another and I rlly can’t think of a way to make a variable that fits these requirements. The closest to successful result I have at the moment is using global variables which complete almost every check except that all clones of each enemy type share one health bar, it’s reset whenever a new clone is made, and when one clone dies all clones die due to the shared hp.

Here’s the game for reference: Survival Shooter V0.2 by guile | Snap! Build Your Own Blocks

What you want to do is use Survival Shooter V0.2 script pic
Then use this to make an HP variable for each clone by putting it in the "when I start as a clone" script.

What you can do is use script variables like nerdiot said, and instead of having the projectile check if it is touching the clone, you should have the clond check if it is touching the projectile.

Also, you don't need to do Survival Shooter V0.2 script pic (2) since
Survival Shooter V0.2 script pic (3) will report true anyways. If you want to check if it is false though, you can use Survival Shooter V0.2 script pic (5).

Problem with this at least in my testing is that the clones can’t detect if that projectile has been released, aka there isn’t any effective cheese prevention because the projectile can’t really tell the sprites it’s been released, especially when there can be multiple coexisting at the same time, at least from what I’ve tested.

I used script variables initially but the best way to prevent this I was able to find was by adding a if block for when the charging key (lmb) was held down or not, but this meant that if you were timing your charges well your shots would stop damaging enemies around halfway through, if not earlier

The only way I’ve been able to actually prevent this is adding a wait block onto the projectile instead and adding in the script for the damage afterward, which means the damage script doesn’t apply until the projectile is released. This has the aforementioned effect of having shared health due to a lack of variables specific to each clone outside of script variables which can’t be transferred between scripts or sprite, clearly, by the name

I’m trying to find a solution that damages enemies in path upon release and prevents cheese through waving a charged projectile around to easily kill all enemies near you as that just makes the game not fun to play unless you purposely try to ignore this pretty much game beating bug

  • possibly optional but it would be much simpler for me if the sprite’s weapons and/or projectiles can see these variables/health state, though I’m partway through making it so that isn’t necessary

If you use untitled script pic (28) then other sprites can see sprite-local variables.

If you say


(where FOO is the sprite-local variable) then all clones will share the same copy. But to keep that relationship, the clones can't directly change the variable. Instead they have to say

In principle, inheriting of script variables should be the default, but as it turns out the assignment of serial numbers to clones with


is too common and too useful for us to break it.

Was able to get it to work by doing this based off what you told me, thanks :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.