And thanks for the comments everyone.
Edited by flexaplex, 21 March 2009 - 01:23 PM.
Posted 21 March 2009 - 01:16 PM
Edited by flexaplex, 21 March 2009 - 01:23 PM.
Posted 21 March 2009 - 01:45 PM
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?Posted 21 March 2009 - 02:03 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. This is probably because the operators are evaluating things 'correctly' however the round to even is used when evaluating single expressions.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.
Edited by flexaplex, 21 March 2009 - 04:29 PM.
Posted 21 March 2009 - 06:03 PM
Posted 21 March 2009 - 09:57 PM
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!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.
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.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.
Posted 21 March 2009 - 10:53 PM
Edited by Them, 21 March 2009 - 10:53 PM.
Posted 21 March 2009 - 10:58 PM
Posted 21 March 2009 - 11:00 PM
Posted 21 March 2009 - 11:25 PM
Posted 22 March 2009 - 12:26 AM
Posted 22 March 2009 - 01:16 AM
Posted 22 March 2009 - 08:47 PM
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.
Posted 26 March 2009 - 04:02 AM
Posted 26 March 2009 - 09:01 AM
Posted 26 March 2009 - 01:14 PM
The return statement is covered in the guide under the scripts section: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?
For the example of returning x. Say you have a script called get_x and you you used this code: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.
x = 5; return 5;
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.
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.add a bit about paths and a few examples and it would be almost perfect
Edited by flexaplex, 26 March 2009 - 01:15 PM.
Posted 26 March 2009 - 09:22 PM
The return statement is covered in the guide under the scripts section: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?
For the example of returning x. Say you have a script called get_x and you you used this code: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.
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.
Posted 27 March 2009 - 02:55 AM
Posted 27 March 2009 - 11:14 AM
Posted 28 March 2009 - 10:36 AM
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.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.
Edited by flexaplex, 28 March 2009 - 10:37 AM.
0 members, 1 guests, 0 anonymous users