Page 1 of 1

My name is Jason and I would love some if relative help

PostPosted: Mon Apr 10, 2017 1:41 am
by Myst
*(Game Editor)


GML stands for Game Maker Language


Here is a working GML of if relative:


Create Event
Code: Select all
hp = 124; //variable hp is 124
hp_divided_by = 1; //will be used to divide hp
hp_minus = 0; //will be used to reduce hp
hp_plus = 0; //will be used to increase hp
hp_times_by = 1; //will be used to multiply hp



Step Event
Code: Select all
if (hp_times_by <> 0) //if hp_times_by more/less than 1
{
  hp *= hp /= hp_times_by; //hp times by hp_times_by
  hp_times_by = 1; //hp_times_by equals 1
}
if (hp_minus <> 0) //if hp_minus is less or more than 0
{
  hp -= hp_minus; //hp reduced by hp_minus
  hp_minus = 0; //hp_minus equals to 0
}
if (hp_plus <> 0) //if hp_plus is more or less than 0
{
  hp += hp_plus; //hp gets increased hp_plus
  hp_plus = 0; //hp_plus equals to 0
}
if (hp_divided_by <> 1) //self explanitory
{
  hp /= hp_divided_by; //hp divided by hp_divided_by
  hp_divided_by = 1; //hp_divided_by equals to 1
}
if (hp_divided_by = 12) //if hp_divided_by equals 12
{
  x += 13; //go right by thirteen pixels
}
if (hp_minus = 12) //if hp_minus equals 12
{
  y += 13; //go down by 13 pixels
}
if (hp_plus = 12) /if hp_plus equals 12
{
  y -= 13; //go up by thirteen pixels
}
if (hp_times_by = 12) //if hp_times_by equals 12
{
  x -= 13; //go left by 13 pixels
}
if (keyboard_check_pressed(ord("T))) //if T is pressed
{
  hp_times_by = 12; //hp_times_by equals to 12
}
if (keyboard_check(ord("P"))) //if P is pressed
{
  hp_plus = 12; //hp_plus equals to 12
}
if (keyboard_check_pressed(ord("M")))//if M is pressed
{
  hp_minus = 12; //hp_minus equals to 12
}
if (keyboard_check_pressed(ord("D"))) //if D is pressed
{
  hp_divided_by = 12; //hp_divided_by equals to 12
}



How in Game Editor do I properly do up above coding please? Thank you.

Re: My name is Jason and I would love some if relative help

PostPosted: Mon Apr 10, 2017 9:30 am
by MrJolteon
Welcome to the forums!

Code: Select all
if (hp_times_by <> 0) //if hp_times_by more/less than 1
{
  hp *= hp /= hp_times_by; //hp times by hp_times_by
  hp_times_by = 1; //hp_times_by equals 1
}
if (hp_minus <> 0) //if hp_minus is less or more than 0
{
  hp -= hp_minus; //hp reduced by hp_minus
  hp_minus = 0; //hp_minus equals to 0
}
if (hp_plus <> 0) //if hp_plus is more or less than 0
{
  hp += hp_plus; //hp gets increased hp_plus
  hp_plus = 0; //hp_plus equals to 0
}
if (hp_divided_by <> 1) //self explanitory
{
  hp /= hp_divided_by; //hp divided by hp_divided_by
  hp_divided_by = 1; //hp_divided_by equals to 1
}
if (hp_divided_by = 12) //if hp_divided_by equals 12
{
  x += 13; //go right by thirteen pixels
}
if (hp_minus = 12) //if hp_minus equals 12
{
  y += 13; //go down by 13 pixels
}
if (hp_plus = 12) /if hp_plus equals 12
{
  y -= 13; //go up by thirteen pixels
}
if (hp_times_by = 12) //if hp_times_by equals 12
{
  x -= 13; //go left by 13 pixels
}


This part is more or less identical in GE.
The variables can either be declared in the script, which only makes them usable within that one script, this is done like this:
Code: Select all
int hp;
int hp_divided_by;
// etc.

Or they can be declared in global code the same way, or via the Variables button found in the script editor. These are available globally.

As for the key press checks, those are done differently, but I don't know how. You'll have to wait for someone else to help you with that.

Re: My name is Jason and I would love some if relative help

PostPosted: Mon Apr 10, 2017 12:23 pm
by juansimat
For the key press check you have several ways, but basicaly you have two important options:
You can listen to key down and key up events to take action directly or, via script, use the function GetKeyState() to check all the keys you want.

Code: Select all
char *keys = GetKeyState(); //Get complete keyboard state

if(keys[KEY_t] == 1) //if T is pressed
{
  hp_times_by = 12; //hp_times_by equals to 12
}
if (keys[KEY_p] == 1) //if P is pressed
{
  hp_plus = 12; //hp_plus equals to 12
}
if (keys[KEY_m] == 1)//if M is pressed
{
  hp_minus = 12; //hp_minus equals to 12
}
if (keys[KEY_d] == 1) //if D is pressed
{
  hp_divided_by = 12; //hp_divided_by equals to 12
}


Warning: I noticed you used keyboard_check and keyboard_check_pressed.
The way I showed is more likely to be put into a draw event (i.e, runs every frame) so it will work like keyboard_check. If you want to achieve the effect of keyboard_check_pressed, you can use that code into a keydown without repeat (repeat disabled). Or code your own keyboard state.

Re: My name is Jason and I would love some if relative help

PostPosted: Thu Apr 13, 2017 12:18 pm
by lcl
For relational operators (less than, greater than, equal, not equal, etc.) you can check this link: https://www.tutorialspoint.com/cprogram ... rators.htm

Also, welcome to the forums! :)

Re: My name is Jason and I would love some if relative help

PostPosted: Wed May 03, 2017 7:03 am
by millepix
For relational operators (less than, greater than, equal, not equal, etc.) you can check this link: https://www.tutorialspoint.com/cprogram%20...%20rators.htm


Thank you for that link. :)