This is my first time writing IFs in dm.. but I guess this should be one of the easier things to learn.. (I hope).. but should be baby steps for most people..
Made these changes:
proc/Angle(atom/A, atom/B)
if (A.x==B.x) return 0
if (A.x<B.x && A.y<=B.y) return 90-arctan((A.y-B.y)/(A.x-B.x)) //This looks at NE quadrant only
*Note: This will be completed below*
instead of original:
proc/Angle(atom/A, atom/B)
return 90-arctan((A.y-B.y)/(A.x-B.x))
.. So now every time I click on a tile directly above or below my character, I don't get an error message anymore ! Because it would just return a value of 0 to the console, instead of the 90-arctan bit..
Reference here
So I guess if I wanted to complete the whole thing (with 0 being North)
proc/Angle(atom/A, atom/B)
if (A.x==B.x && A.y<=B.y) return 0 //for directly north
if (A.x==B.x && A.y>=B.y) return 180 //for directly south
if (A.x<B.x && A.y<=B.y) return 90-arctan((A.y-B.y)/(A.x-B.x)) //This looks at NE quadrant only
if (A.x<B.x && A.y>=B.y) return 90+arctan((A.y-B.y)/(A.x-B.x)) //This looks at SE quadrant only
if (A.x>B.x && A.y>=B.y) return 270-arctan((A.y-B.y)/(A.x-B.x)) //This looks at SW quadrant only
if (A.x>B.x && A.y<=B.y) return 270+arctan((A.y-B.y)/(A.x-B.x)) //This looks at NW quadrant only
Each if is condensed in one line at the moment. But I can write it in separate line just as you would in C++ using {} brackets (I think).. or in VBA using 'if' .. 'end if', e.g. I could try rewriting the logic above differently like:
proc/Angle(atom/A, atom/B)
if (A.x==B.x)
if (A.y<=B.y) return 0
else return 180
else if (A.x<B.x)
if (A.y<=B.y) return 90-arctan((A.y-B.y)/(A.x-B.x)) //This looks at NE quadrant only
else return 90+arctan((A.y-B.y)/(A.x-B.x)) //This looks at SE quadrant only
else
if (A.y>=B.y) return 270-arctan((A.y-B.y)/(A.x-B.x)) //This looks at SW quadrant only
else return 270+arctan((A.y-B.y)/(A.x-B.x)) //This looks at NW quadrant only
.. I realised I'm repeating arctan((A.y-B.y)/(A.x-B.x)) a lot.. there must be a way of making this more concise right? But I guess I wouldn't bother with that.. it's not like I can win those 8KB competitions or something
.. but either way still gives me desired results anyway :)
Well, I'm back.. and just tried to figure out what Lummox mentioned last time out.
So here's the first thing I needed to learn :
So I understand now.. I had to modify my codes to do something like this:
instead of what I did earlier:
.. Especially if I used this proc in another place, and the usr and src are different.. I think I get it now :D
***
On the other hand, to call this proc, I now needed to have
**Note: This will be edited again below**
instead of what I had earlier:
Right.. let's see what else I can learn before the weekend is up :p
*****
So moving on to point #3 from Lummox..
.. I'm so slow I took 10mins to understand how to use it first of all [so I had to change "var/n = atan2(usr,src)" instead of "var/n = Angle(usr,src)" in my rotate() verb. ]..
.. but still don't understand how you got those numbers :p (but it works obviously).. although it's giving me between 0 to 90 deg. Maybe I'll try and figure out how to get it to 360.. hmm..
*****
Well, to do point #4, I thought I might as well make this another "lesson" because I need to learn about writing if statements in DM (pretty trivial I know :p).. but I keep forgetting.. and I guess it's nice to see my own thought process in learning this