Author [EN] [PL] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [ID] Topic: Possibly very useful important tip for Game Maker users  (Read 774 times)

0 Members and 1 Guest are viewing this topic.

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1825
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Possibly very useful important tip for Game Maker users
« on: May 17, 2012, 06:31:48 PM »
0
This might not be new to some people here, or maybe it's new to all of us here. I know it's in other languages, I think, like C or something, since I think it's where I got the idea from.

So I was thinking today, you can put a function like instance_create() inside parentheses in order to use it as an operand in conditionals or formulas. For example, if (instance_create(x,y,current_weapon)).object_index==obj_HexMiss is a valid conditional. The simple question is, why does that work and not if instance_create(x,y,current_weapon).object_index==obj_HexMiss and the answer is just as simple: the parentheses tell GM what operation to perform first. This is a computer, so instance_create() is still technically a mathematical operation and it therefor follows that parentheses are needed to tell it to be performed before the rest of the operation.

So I asked myself, why can't the same be true for a conditional like x<4? So I ran a test. My hypothesis was if x<4 was the same as if 1 if indeed x was less than 4; therefor (x<4) should also be the same as 1 or 0 any time it was used. So to test this, I ran in debug mode and created the global variable a. I then set a=-1. Then I watched the expression 4^$FF*(a>-1). Now, since a was set to -1, the expression, if it was indeed valid, should return 4^0, which is 4. Sure enough, that was the case with no error displayed. So in theory, setting a=1 should change the result to $FB. That indeed was the case.

So in short summary, you can use conditionals, which return 0 or 1, or any function/script which returns a value (most built-in functions in GM do in fact return a value) within any mathematical operation in GM.

respect += (respect>35)

« Last Edit: May 17, 2012, 06:36:23 PM by TheouAegis »
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Tags:
 

anything