I am making an RPG. This script is for moving the character, but it doesn't work correctly..
when gf clicked forever if <key [down arrow] pressed?> set [ypos] to [-0.4] else set [ypos] to [0] end if <key [up arrow] pressed?> set [ypos] to [0.4] else set [ypos] to [0] end if <key [left arrow] pressed?> set [xpos] to [-0.4] else set [xpos] to [0] end if <key [right arrow] pressed?> set [xpos] to [0.4] else set [xpos] to [0] end change x by (xpos) change y by (ypos)what it basically does is moves the character by the variable and x or y gets changed by the character.
Offline
The "else" statements are overriding the earlier actions of the "if" statements - for example, if "down" is pressed, you set "ypos" to -0.4 but at the next statement, "up" isn't pressed and so sets ypos to 0 instead - hope i've explained that properly!
Offline
ScratchOS wrote:
I am making an RPG. This script is for moving the character, but it doesn't work correctly..
when gf clicked forever if <key [down arrow v] pressed?> set [ypos v] to [-0.4] else set [ypos v] to [0] end if <key [up arrow v] pressed?> set [ypos v] to [0.4] else set [ypos v] to [0] end if <key [left arrow v] pressed?> set [xpos v] to [-0.4] else set [xpos v] to [0] end if <key [right arrow v] pressed?> set [xpos v] to [0.4] else set [xpos v] to [0] end change x by (xpos) change y by (ypos)what it basically does is moves the character by the variable and x or y gets changed by the character.
Why you may be asking? This is going to make collision detecting easier so the sensor will touch a colour and change x or ypos.
It works fine for moving upwards and rightwards but you can't go left or down.. please help!!
It doesn't work for the down and left because right after it sets it to 0.4 it checks for the right arrow key, and since the right key isn't pressed, it changes it back to 0. Same with the down key and up key. I suggest using this.
when gf clicked forever if <<not<key [left arrow v] pressed?>> and <not<key [right arrow v] pressed?>>> set [x pos v] to [0] end if <<not<key [up arrow v] pressed?>> and <not<key [down arrow v] pressed?>>> set [y pos v] to [0] end if <key [right arrow v] pressed?> set [x pos v] to [0.4] end if <key [left arrow v] pressed?> set [x pos v] to [-0.4] end if <key [up arrow v] pressed?> set [y pos v] to [0.4] end if <key [down arrow v] pressed?> set [y pos v] to [-0.4] end change x by <x pos> change y by <y pos>I'm almost completely sure that that would work.
Last edited by TorbyFork234 (2012-04-02 15:25:32)
Offline
Offline