Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[SOLVED]Making Switches only effect one event

Status
Not open for further replies.
Before you read any further, I am not looking for how to use switches or Self Switches. This is different.

Hi. For ages I've been developing the ABS for my game. It's all evented, and works perfectly, but I have one problem. A problem that I think can be solved pretty easily with scripts. All of my enemy events are set up so as to read where the actor is in realation to the enemy event through variables. Then when the player fires a gun (it's a shooting game) the enemy will react differently depending on which gun. That all works. Then it checks the enemies health, and if it is bellow a certain variable, the enemy dies. Now here's my problem. This works really well, but it means each enemy must have a unique set of variables for each, so that all the enemies don't die at once. Are you with me so far? Ok.

What I want to know is is there a way with the script part of Conditional Branch to make the same variable store different numbers depending on the event it is being used in? I've tried, and this is what I've come up with, but it doesn't work:

A script entry at the top of the event page says

Name_Of_Event =
$game_map.events[@event_id].event.name

Then the eventing I have already done follows where it checks for what gun is equiped and how far away the player is, ect. Then when the player is in range and fire the gun, I tried the script input

$game_variables[14+Name_Of_Event.to_i] =
$game_variables[14+Name_Of_Event.to_i]
-7

Variable 14 is the enemies health. Then underneath that in the event page it says

Conditional Branch Script

$game_variables[14+Name_Of_Event] <= 20

The enemies event vanishes after there is a falling animation and it flashes. Basically.

So, what am I doing wrong? Can it even be done? Please help.

Thanks,
Fox
 
Whenever I shoot at the enemy, I get

undifinened method '-' for #<ABS_Enemy:0x631dd08 at HP=20>

and I'm using

event.abs_enemy -= 7

to subtract the health. What am I doing wrong?


EDIT: Ah, doesn't matter, I'd forgotten to put .hp after it. Thanks again for all your help. It works perfectly.
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top