Windows Power Bar Mechanic in FNaF

S

StickyFrog10

Guest
FNaF Power Bar

Hey guys! I'm currently making a new FNaF Fan Game on Gamemaker Studio, and it will be my first game!
Does anybody know how to do a power bar mechanic?
What I mean is for ex. (Normally I stay in the office, I lose 1% every 7 seconds, but if I close the door, I lose 2% every 7 seconds)
Anyone who knows how to do this mechanic, please comment below. I will be appreciated for your help!
 

MaxLos

Member
FNaF Power Bar

Hey guys! I'm currently making a new FNaF Fan Game on Gamemaker Studio, and it will be my first game!
Does anybody know how to do a power bar mechanic?
What I mean is for ex. (Normally I stay in the office, I lose 1% every 7 seconds, but if I close the door, I lose 2% every 7 seconds)
Anyone who knows how to do this mechanic, please comment below. I will be appreciated for your help!
If you want to lose 1% or 2% exactly every 7 seconds, you could do something like this:
Code:
//Create Event

power = 100; //Remaining power
door_opened = false;  //Whether or not the door is opened
alarm[0] = room_speed * 7; //7 seconds
Code:
//Alarm 0 Event

if (door_opened = true) power -= 1; // Door is open, subtract 1 from power
else power -= 2; //Door is closed, subtract 2 from power
alarm[0] = room_speed * 7; //Reset alarm
Although.. if a player really wanted to they could save power by keeping the door closed and opening it right before the 7 second mark. To avoid that you would have to deplete the energy over time so you could do this instead

Code:
//Create Event

power = 100; //Remaining power
door_opened = false; //Whether or not the door is opened
power_drain = 0;
Code:
//Step Event
if (door_opened = true) power_drain = 0.00238; //Roughly about 1% every 7 seconds (60 fps)
else power_drain = 0.00476; //Roughly about 2% every 7 seconds

power -= power_drain
Also, don't ask the same question twice in two different sections lol
 
S

StickyFrog10

Guest
If you want to lose 1% or 2% exactly every 7 seconds, you could do something like this:
Code:
//Create Event

power = 100; //Remaining power
door_opened = false;  //Whether or not the door is opened
alarm[0] = room_speed * 7; //7 seconds
Code:
//Alarm 0 Event

if (door_opened = true) power -= 1; // Door is open, subtract 1 from power
else power -= 2; //Door is closed, subtract 2 from power
alarm[0] = room_speed * 7; //Reset alarm
Although.. if a player really wanted to they could save power by keeping the door closed and opening it right before the 7 second mark. To avoid that you would have to deplete the energy over time so you could do this instead

Code:
//Create Event

power = 100; //Remaining power
door_opened = false; //Whether or not the door is opened
power_drain = 0;
Code:
//Step Event
if (door_opened = true) power_drain = 0.00238; //Roughly about 1% every 7 seconds (60 fps)
else power_drain = 0.00476; //Roughly about 2% every 7 seconds

power -= power_drain
Also, don't ask the same question twice in two different sections lol




Hey, when I copied the code, I got two errors. Here they are:
In Object oPowerBar, in Event CreateEvent action number 1 at line 1 : cannot use function/script name for a variable, using "power"
In Object oPowerBar, in Event StepNormalEvent action number 1 at line 3 : cannot use function/script name for a variable, using "power"
How to fix them?
 

TailBit

Member
there is a function that have that name power already, you need to rename the variables into something else

power it is a math operation function, power(2,5) tells 2 to multiply with itself 5 times .. so 2*2*2*2*2

could just rename them to:
door_power

or something shorter..
 
S

StickyFrog10

Guest
there is a function that have that name power already, you need to rename the variables into something else

power it is a math operation function, power(2,5) tells 2 to multiply with itself 5 times .. so 2*2*2*2*2

could just rename them to:
door_power

or something shorter..
wait, so do I need to type the code that the person gave me earlier in the code thing, or a variable?
 

TailBit

Member
you just need to rename all the occurrences of the word "power" in his code into something else (those without a _ connected word)
 
S

StickyFrog10

Guest
you just need to rename all the occurrences of the word "power" in his code into something else (those without a _ connected word)
For some reason my power bar percent dosen't decrease
 

MaxLos

Member
there is a function that have that name power already, you need to rename the variables into something else

power it is a math operation function, power(2,5) tells 2 to multiply with itself 5 times .. so 2*2*2*2*2

could just rename them to:
door_power

or something shorter..
Oh yeah, there is. Whoops

For some reason my power bar percent dosen't decrease
Are you sure? Did you do what tailbit said about renaming the "power" variable? Draw out the value just to make sure
 
S

StickyFrog10

Guest
Oh yeah, there is. Whoops



Are you sure? Did you do what tailbit said about renaming the "power" variable? Draw out the value just to make sure
what kind of variable do I need?
 

FrostyCat

Redemption Seeker
Stop, just stop. Time out on FNAF or whatever your dream game is. There is no point in that if you don't even know what a variable or event does. Follow a basic tutorial like this one, learn the basic lingo and techniques of this trade, make some basic prototypes, then start building your dream game once you stop needing help with elementary tasks.

Fangamers and star-eyed rookies who won't take time off their dream to build a foundation have a near 100% flop rate, and that has been consistent throughout my 15 year stay on these forums.
 
Top