N
NoFontNL
Guest
Hi all! I am making a CPU for a game. It's a 2D shooting game. But that doesn't matter. To get straight to the point, let's take a look at my code.
Me :: obj_player_red
Bot :: obj_bot
Where I placed a comment 'HERE!!' is where I somehow messed up. If you have full ammo, you have 5 bullets.
Don't ask me why I did the
because it is hard to explain, and yes, this code is needed.
The real problem: I want the bot to shoot when I shoot, but because of the code the bot won't shoot when I've 1 bullet left and when he has 1 bullet left. Because:
if !(ammo == 1 && obj_player_red.ammo == 0) {
First statement TRUE
Second statement FALSE
with the ! before it, it will reverse, but because of the &&, it will still return false, so it won't shoot.
I want the bot not to shoot when I've 0 ammo and when the bot has 1 ammo. So when both statemetns are both exactly what they are. So not when one statement is false that the whole statement between () is false.
To shorten everything:
How would I get it, that the if statement doesn't return false, when one of the statements inside it is false, but only when both of the statements are false.
So litterally if NOT (obj_player_red.ammo ==0 AND obj_bot.ammo==1) scr_bot_shoot
(When obj_player_red.ammo is 0 at the same time as obj_bot.ammo is 1) ** so not that if only obj_bot.ammo ==1 that it will return false.
I still don't exactly know how to explain it, but here's another explanation if you don't understand.
I've made this:
If both of the disable variables return true, the bot can't shoot.
If one (or both) of the disable variables return false, I want the bot to shoot ( when you press spacebar )
But the bot doesn't shoot when I've 1 ammo and when the bot has 1 ammo (and I press spacebar)
Only I shoot.
Me :: obj_player_red
Bot :: obj_bot
Code:
///Step Event obj_bot
if keyboard_check_pressed(vk_space){ // If you pressed space ...
if (obj_player_red.grounded) { // If you are on the ground
if !(ammo == 1 && obj_player_red.ammo == 0) { // HERE!!
scr_bot_shoot();
} else {
// do nothing
}
}
}
Don't ask me why I did the
Code:
if !(ammo == 1 && obj_player_red.ammo == 0) { // HERE!!
scr_bot_shoot();
} else {
// do nothing
}
The real problem: I want the bot to shoot when I shoot, but because of the code the bot won't shoot when I've 1 bullet left and when he has 1 bullet left. Because:
if !(ammo == 1 && obj_player_red.ammo == 0) {
First statement TRUE
Second statement FALSE
with the ! before it, it will reverse, but because of the &&, it will still return false, so it won't shoot.
I want the bot not to shoot when I've 0 ammo and when the bot has 1 ammo. So when both statemetns are both exactly what they are. So not when one statement is false that the whole statement between () is false.
To shorten everything:
How would I get it, that the if statement doesn't return false, when one of the statements inside it is false, but only when both of the statements are false.
So litterally if NOT (obj_player_red.ammo ==0 AND obj_bot.ammo==1) scr_bot_shoot
(When obj_player_red.ammo is 0 at the same time as obj_bot.ammo is 1) ** so not that if only obj_bot.ammo ==1 that it will return false.
I still don't exactly know how to explain it, but here's another explanation if you don't understand.
I've made this:
Code:
var disable0 = ammo == 1;
var disable1 = obj_player_red.ammo == 0;
var canshoot;
if (disable0) && (disable1) {
canshoot = 0;
} else {
canshoot=1;
}
If one (or both) of the disable variables return false, I want the bot to shoot ( when you press spacebar )
But the bot doesn't shoot when I've 1 ammo and when the bot has 1 ammo (and I press spacebar)
Only I shoot.