Jump to content


Photo
* * * * * 2 votes

The Complete Beginners Guide To Gml Coding


  • Please log in to reply
78 replies to this topic

#21 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4809 posts
  • Version:GM8

Posted 21 March 2009 - 01:16 PM

I think that is a precision error. Try this in debug mode: !(0.5) it comes up false.

And thanks for the comments everyone.

Edited by flexaplex, 21 March 2009 - 01:23 PM.

  • 0

#22 DarkSentinel

DarkSentinel

    GMC Member

  • New Member
  • 1965 posts

Posted 21 March 2009 - 01:45 PM

Yes, I see what you mean. Both (0.5 and 1) and (0.5 or 0) evaluate to true.
But now I'm really confused.
if (.5)
{
  draw_text(0,0,'true')
}
else
{
  draw_text(0,0,'false')
}
Draws false for me. It seems that .5 itself is false but if you use it in a comparison it is true. Is it still a precision issue if I write .5 directly?
BTW the Wikipedia page on GML says that .5 is false as well.
  • 0

#23 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4809 posts
  • Version:GM8

Posted 21 March 2009 - 02:03 PM

Yes, I see what you mean. Both (0.5 and 1) and (0.5 or 0) evaluate to true.
But now I'm really confused.

if (.5)
{
  draw_text(0,0,'true')
}
else
{
  draw_text(0,0,'false')
}
Draws false for me. It seems that .5 itself is false but if you use it in a comparison it is true. Is it still a precision issue if I write .5 directly?
BTW the Wikipedia page on GML says that .5 is false as well.

Yes you are right, it seems 0.5 does actually evaluate to false when used as an expression by itself. I have always used the ! to test this as it is the quickest way so have not seen the result otherwise as 0.5 is evaluating as true when used with operators. This is probably because the operators are evaluating things 'correctly' however the round to even is used when evaluating single expressions.

I do not know really what to put about this in the guide, as far as I am concerned it is really an issue with GM's rounding but mentioning this will just overcomplicate things.

edit: I just tried explaining it in the guide, it wasn't pretty.. I think I will leave this detail out and hope people just read these comments.

Edited by flexaplex, 21 March 2009 - 04:29 PM.

  • 0

#24 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 21 March 2009 - 06:03 PM

Nice guide. Too bad I already know lots of GML and C++ and...
  • 0

#25 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 21 March 2009 - 09:57 PM

Yes you are right, it seems 0.5 does actually evaluate to false when used as an expression by itself. I have always used the ! to test this as it is the quickest way so have not seen the result otherwise as 0.5 is evaluating as true when used with operators.

Hmm, this is very weird... I tested Dark Sentinel code with both !(0.5) and (0.5) and they do indeed seem to give contradicting results! (using GM7) Good spot by Dark Sentinel!

edit: I just tried explaining it in the guide, it wasn't pretty.. I think I will leave this detail out and hope people just read these comments.

Yeah, I think this is best... Your guide is just to cover the basics, and I don't think you want to get into anything 'too' technical.
  • 0

#26 Them

Them

    GMC Member

  • New Member
  • 65 posts

Posted 21 March 2009 - 10:53 PM

This is an awesome tutorial, I already knew much of what was in the first post but it still taught me a few things(still have to read the second one). This was very well-written and easy to understand, I think it could help my cousin out a lot with learning to use Game Maker. Thanks for writing this :)

Edited by Them, 21 March 2009 - 10:53 PM.

  • 0

#27 GammaFoxTBG

GammaFoxTBG

    GMC Member

  • New Member
  • 388 posts

Posted 21 March 2009 - 10:58 PM

Very well written! I learned a couple tricks from this, and a bit more on lists. This definitely covers all the basics, and I hope to reference this to a few friends of mine learning GML. :)
  • 0

#28 Games

Games

    GMC Member

  • Banned Users
  • 2968 posts

Posted 21 March 2009 - 11:00 PM

.5 will round down, 1.5 will round up, 2.5 will round down.

If you really want a 50/50 chance..

if random( 1 ) <= .5

Same goes for a 30/70 chance..

if random( 1 ) <= .3

#29 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 21 March 2009 - 11:25 PM

This is a very long and well-written guide. Great job, and hope some people will learn things from this. :D

This is definitely going to be useful to new people out there. :)
  • 0

#30 jengajam

jengajam

    GMC Member

  • GMC Member
  • 522 posts

Posted 22 March 2009 - 12:26 AM

Wow this is a great guide, I really wish I had this when starting off! :) 10/10
  • 0

#31 Nami

Nami

    GMC Member

  • New Member
  • 1 posts

Posted 22 March 2009 - 01:16 AM

Thanks for this. Very helpful.
  • 0

#32 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4809 posts
  • Version:GM8

Posted 22 March 2009 - 08:47 PM

Thanks for all the comments guys. I hope this guide can make it's way into the hands of a proper beginner at some point, I want to see how easily they take to it.
  • 0

#33 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 26 March 2009 - 03:43 AM

Thanks for all the comments guys. I hope this guide can make it's way into the hands of a proper beginner at some point, I want to see how easily they take to it.


Well, I'll be linking beginners to this for sure!
  • 0

#34 asfastasdark

asfastasdark

    GMC Member

  • New Member
  • 55 posts

Posted 26 March 2009 - 04:02 AM

I remember using arguments instead of variables when I didn't use them for scripts because I didn't know how global and local variables worked :)...

Could you explain this to me though: What does the return statement do? Say I put "return x" in a piece of code and x was equal to 5. What would that do?
  • 0

#35 joethedumblr

joethedumblr

    GMC Member

  • New Member
  • 253 posts

Posted 26 March 2009 - 09:01 AM

add a bit about paths and a few examples and it would be almost perfect
  • 0

#36 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4809 posts
  • Version:GM8

Posted 26 March 2009 - 01:14 PM

Could you explain this to me though: What does the return statement do? Say I put "return x" in a piece of code and x was equal to 5. What would that do?

The return statement is covered in the guide under the scripts section:

Instead of values you put into a script this is a actually a value that the script gives out to the instance calling it. For example if you set up a script called multiply:

//multiply() multiplies numbers
var sum;
sum = 4*5;
return sum;

note: I have declared the sum variable using var, this practice should always be made with variables used only in the script.

This will calculate the sum as 20 and then it will return the value, so basically this script is going to return 20. Now if you call this from an object using a variable assignment like so:

value = multiply();

It is going to first execute the script which is going to return 20, this return value will then be assigned to the variable value. So now the variable value will be equal to 20.

For the example of returning x. Say you have a script called get_x and you you used this code:

scr get_x:
x = 5;
return 5;

Then when you call this script it will return (give) you a value of 5 from it. Ie if you use this code:

x_value = get_x();
The variable x_value will now be set to 5 as the script get_x will be returning the value 5. Generally though you only want to be using return values when you have actually calculated something not just a variable you have set yourself.

If you understood this explanation but not the explanation in the guide can please explain what part of the guide was not explained well enough for you to understand it in the first place as I am always looking to improve it. Or if you still don't understand please say also and I will try to explain further be specific about what part you still don't understand though.

add a bit about paths and a few examples and it would be almost perfect

Paths are not really covered in 'gml basics' this is more about teaching the basic framework of coding not specific functionality of GM. There was plans to add a topic on paths to the general FAQ however it has not been done yet, I would probably want Icuurd's involvement in doing so however he is still working on other projects at the moment.

Edited by flexaplex, 26 March 2009 - 01:15 PM.

  • 0

#37 asfastasdark

asfastasdark

    GMC Member

  • New Member
  • 55 posts

Posted 26 March 2009 - 09:22 PM

Could you explain this to me though: What does the return statement do? Say I put "return x" in a piece of code and x was equal to 5. What would that do?

The return statement is covered in the guide under the scripts section:

Instead of values you put into a script this is a actually a value that the script gives out to the instance calling it. For example if you set up a script called multiply:

//multiply() multiplies numbers
var sum;
sum = 4*5;
return sum;

note: I have declared the sum variable using var, this practice should always be made with variables used only in the script.

This will calculate the sum as 20 and then it will return the value, so basically this script is going to return 20. Now if you call this from an object using a variable assignment like so:

value = multiply();

It is going to first execute the script which is going to return 20, this return value will then be assigned to the variable value. So now the variable value will be equal to 20.

For the example of returning x. Say you have a script called get_x and you you used this code:

scr get_x:
x = 5;
return 5;

Then when you call this script it will return (give) you a value of 5 from it. Ie if you use this code:

x_value = get_x();
The variable x_value will now be set to 5 as the script get_x will be returning the value 5. Generally though you only want to be using return values when you have actually calculated something not just a variable you have set yourself.

If you understood this explanation but not the explanation in the guide can please explain what part of the guide was not explained well enough for you to understand it in the first place as I am always looking to improve it. Or if you still don't understand please say also and I will try to explain further be specific about what part you still don't understand though.


Ah, thanks so much. I was already thinking that something like that is what was meant, but I wasn't sure. Thanks :(.
  • 0

#38 crusaderdesignproject

crusaderdesignproject

    GMC Member

  • GMC Member
  • 249 posts
  • Version:GM8.1

Posted 27 March 2009 - 02:55 AM

This is amazing! Thank you!!!! I suck at GML so it helps.
  • 0

#39 Mega_Virus

Mega_Virus

    GMC Member

  • New Member
  • 221 posts

Posted 27 March 2009 - 11:14 AM

I appreciate the effort flexaplex put in to this, there's not many tutorials the come close to teaching GML aswell as this topic.
I have learned a bit more about 2D arrays now, just quite alot to grasp at once especially the array eplanation gave me a little head ache but I am starting to get the idea of 2D arrays only because I practiced with the example provided otherwise I would be stuck still, although it is still a little blury to me on ways to use them besides just drawing the values in them. I think mostly what got me confused with the explanation is that he added dis_list, I thought that shouldn't have been mention together with 2d arrays.
  • 0

#40 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4809 posts
  • Version:GM8

Posted 28 March 2009 - 10:36 AM

I appreciate the effort flexaplex put in to this, there's not many tutorials the come close to teaching GML aswell as this topic.
I have learned a bit more about 2D arrays now, just quite alot to grasp at once especially the array eplanation gave me a little head ache but I am starting to get the idea of 2D arrays only because I practiced with the example provided otherwise I would be stuck still, although it is still a little blury to me on ways to use them besides just drawing the values in them. I think mostly what got me confused with the explanation is that he added dis_list, I thought that shouldn't have been mention together with 2d arrays.

I mentioned a few times when explaining 2D arrays that you may find them complicated and code may prove difficult to understand. I cannot really think of an easier way to explain them, they are likely to be a difficulty concept to fully understand for a beginner, especially when for loops are also involved. I think really they are one of those things that is best learnt more by messing around with code yourself.

As for the ds_list's I had a choice, either make ds_list's follow on by putting them after 1D arrays or make 2D arrays follow on by adding them after 1D arrays. As said several times in the guide ds_list's are just an expansion of a 1D array which is why I wanted them explained straight after, so I had to sacrifice 2D arrays not following so ds_lists could. A ds_list is more similar to a 1D array than a 2D array is similar to a 1D in my opinion.

Edited by flexaplex, 28 March 2009 - 10:37 AM.

  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users