|
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Flamer The last guy on earth...
Joined: 04 Feb 2003 Posts: 725 Location: New Zealand (newly discovered)
|
Posted: Tue Feb 24, 2004 2:46 am Post subject: |
|
|
Code: | walk hero (me,((herodirection(me)+2),mod, 4) ,1) |
i suggest revising this part of the code.
because the mod operator should only be returning "false (zero)" or "true (one)"
this means that the hero will only be travelling north or east, as the direction... (found in plotscr.hsd)
maybe you meant.
Code: | walk hero (me,((herodirection(me)+2),divide, 4) ,1) |
where it'll return a number... _________________ If we were a pack of dogs, IM would be a grand Hound, CN would be a very ficious little pitball, and Giz...well, it doesn't matter breed he is, he'd still be a bitch
(no offense to anyone that was mentioned) |
|
Back to top |
|
|
Cube Dimensional Traveller
Joined: 02 Feb 2003 Posts: 294
|
Posted: Tue Feb 24, 2004 8:49 am Post subject: |
|
|
While I'm at school and can't check the directional values (I think up is 0, right is 2, left is 1 and down is 3), I can explain the mod function .
Mod never returns 0 or 1 (In the sense of true and false. It can if those numbers are the remainders). You can think of it as a number being subtracted by another number until it can't be subtracted any longer, and the remainder is given. For example:
10, mod, 3
10 is greater than 3, so subtract 3.
7 is greater than 3, so subtract 3.
4 is greater than 3, so subtract 3.
1 isn't greater than 3, so return 1.
Another example:
15, mod, 4
15 is greater than 4, so subtract 4.
11 is greater than 4, so subtract 4.
7 is greater than 4, so subtract 4.
3 isn't greater than 4, so return 3.
Now, it's not like the mod function itself is running a loop that is continuously subtracting the 2nd number from the 1st. That's just the best way I could explain it . If you want to know an equation for it, I guess I could post that too but for now I won't bother since it isn't really that important.
So anyhow, there you go. Using mod was a much better thing to use than divide, but I can't tell how well it really works, heheh.
If you want to do some mod calculations real quick, I have a simple console app that I made:
Mod Calculator |
|
Back to top |
|
|
xaero me
Joined: 30 Dec 2003 Posts: 101 Location: somewheres
|
Posted: Tue Feb 24, 2004 6:27 pm Post subject: |
|
|
the Mad Cacti's script was working, but i want him to face left from the current direction that he is facing , at the moment he just faces west and the same for right he just east
________
Toyota AD engine history
Last edited by xaero on Thu Feb 03, 2011 7:53 am; edited 1 time in total |
|
Back to top |
|
|
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Tue Feb 24, 2004 11:26 pm Post subject: |
|
|
Cube: directions are 0=up, 1=left, 2=down, 3=right. So you can see that (x + 2), mod, 4 returns the opposite direction to any direction.
Flamer: An easier way to invision modulus is as the remainder to a division. 13 / 3 is 4 with a remainder of 1, and
4 * 3 + 1 = 13
As a random side note:
REMEMBER, the 'logic' functions (and, or, xor, etc) supplied with HamsterSpeak are not technically logical funuctions, but bitwise functions. And modulus has a different meaning is mathematics and programming.
Ok, xearo, I didn't think of that. Heres a finished script:
Code: |
script,boat,begin
suspend player
set tag(3, on)
while(check tag(3)==on) do(
if (key is pressed(key:left)) then (set hero direction(me,((herodirection(me)+3),mod, 4)))
if (key is pressed(key:right)) then (set hero direction(me,((herodirection(me)+1),mod, 4)))
if (key is pressed(key:down)) then (walk hero(me,herodirection(me),1), wait for hero(me))
if (key is pressed(key:up)) then (walk hero (me,((herodirection(me)+2),mod, 4) ,1), wait for hero(me))
if (hero x == 16, and, hero y == 65) then (set tag (3, off))
wait
)
resume player
end
|
As the final note, note I used +3 instead of --1 to turn left. -1, mod, 4 would return -3 (I think. Or was it -1?), which is a deadly and annoying 'feature'. _________________ "It is so great it is insanely great." |
|
Back to top |
|
|
xaero me
Joined: 30 Dec 2003 Posts: 101 Location: somewheres
|
Posted: Wed Feb 25, 2004 7:29 pm Post subject: |
|
|
Thanks for all the help its finnaly running now, and hopefully i know more about scripts and should be able to figure it out next time
________
Subaru EJ engine history
Last edited by xaero on Thu Feb 03, 2011 7:55 am; edited 1 time in total |
|
Back to top |
|
|
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Wed Feb 25, 2004 11:48 pm Post subject: |
|
|
Few people would know how to/when to/would use the bitwise and math functions for this sort of thing. However, using them can sometimes be a great shortcut. _________________ "It is so great it is insanely great." |
|
Back to top |
|
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|