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

Game Editor comments and discussion.

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

Postby Myst » Mon Apr 10, 2017 1:41 am

*(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.
Myst
 
Posts: 5
Joined: Sat Apr 08, 2017 8:24 am
Score: 0 Give a positive score

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

Postby MrJolteon » Mon Apr 10, 2017 9:30 am

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.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

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

Postby juansimat » Mon Apr 10, 2017 12:23 pm

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.
̿̿¯̿̿¯̿̿'̿̿̿̿̿̿̿'̿̿'̿̿̿̿̿'̿̿̿)͇̿̿)̿̿̿̿ '̿̿̿̿̿̿\̵͇̿̿\з=(๏̯͡๏)=ε
User avatar
juansimat
 
Posts: 152
Joined: Sat Dec 19, 2009 8:23 am
Score: 27 Give a positive score

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

Postby lcl » Thu Apr 13, 2017 12:18 pm

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! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

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

Postby millepix » Wed May 03, 2017 7:03 am

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. :)
millepix
 
Posts: 12
Joined: Tue Jan 24, 2017 3:44 am
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron