Syntax problem, how is then missing in this statement
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Syntax problem, how is then missing in this statement
..........
Last edited by [-hh] on Wed Aug 13, 2014 4:16 pm, edited 1 time in total.
shiftLock happens
Re: Syntax problem, how is then missing in this statement
OK Back, sorry I took so long but there was an interesting Android problem.
So, sticky... I get it.
Here's the deal, once an object (Player) has intersected another object (Wall) it has an overlap of say 1 pixel, I'm sure that isn't accurate but for the sake of imagining the situation lets say it has. No matter which way you want the Player to go the first thing it notices is that it's already intersecting Wall, so... it's first instruction is "If I touch Wall Stop Moving" and it does that and it is shown by the "sticking".
Hermann's Ctrl+ArrowKey is an instruction to ignore intersect all together and the result is no sticking.
Bouncing. This entails that when Player intersects Wall it immediately heads in the opposite direction (note not Stop Moving). If the arrowKey is up and the Player hits a Wall above it then the Player would move down regardless of the arrowKey. The effect if you keep pressing the arrowKey up is Player will "bounce".
chaucer345,
I have no idea what to do with the last code you posted, I made a stack with 4 images and 10 rectangles all named correctly, this line;
is completely whacked out.
You must use Object Type and Name, the line only has Name.
Craig mentioned this to you already.
Simon
So, sticky... I get it.
Here's the deal, once an object (Player) has intersected another object (Wall) it has an overlap of say 1 pixel, I'm sure that isn't accurate but for the sake of imagining the situation lets say it has. No matter which way you want the Player to go the first thing it notices is that it's already intersecting Wall, so... it's first instruction is "If I touch Wall Stop Moving" and it does that and it is shown by the "sticking".
Hermann's Ctrl+ArrowKey is an instruction to ignore intersect all together and the result is no sticking.
Bouncing. This entails that when Player intersects Wall it immediately heads in the opposite direction (note not Stop Moving). If the arrowKey is up and the Player hits a Wall above it then the Player would move down regardless of the arrowKey. The effect if you keep pressing the arrowKey up is Player will "bounce".
chaucer345,
I have no idea what to do with the last code you posted, I made a stack with 4 images and 10 rectangles all named correctly, this line;
Code: Select all
set the top of line x of characterSprites to the top of line x of characterSprites - playerSpeed
You must use Object Type and Name, the line only has Name.
Craig mentioned this to you already.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 23
- Joined: Thu Jul 24, 2014 8:08 pm
Re: Syntax problem, how is then missing in this statement
Here's the code with improved syntax:
What the script is supposed to do is first detect whether there's an intersect, then find out whether the right of the sprite intersects it or the left of the sprite intersects it, or the top or the bottom and then only stop the sprite's movement in the direction of the intersection... Though thinking about it I can see part of the problem, that being that this way would make only one direction available to the player.
Code: Select all
local myWalls
local characterSprites
local numberOfWalls
local intersectsTop
local intersectsBottom
local intersectsLeft
local intersectsRight
local playerSpeed
on preOpenCard
setUpVariables
end preOpenCard
command setUpVariables
--set the player looking to the right at startup
show image "pUp"
show image "pDown"
show image "pLeft"
show image "pRight"
put "pUp" into line 1 of characterSprites
put "pDown" into line 2 of characterSprites
put "pLeft" into line 3 of characterSprites
put "pRight" into line 4 of characterSprites
put 5 into playerSpeed
put 10 into numberOfWalls
repeat with x = 1 to numberOfWalls
put "rectangle" & x into line x of myWalls
end repeat
end setUpVariables
on arrowKey k
if k = "up" then
handleWallCollisions
if intersectsTop = "false" then
repeat with x = 1 to 4
set the top of img line x of characterSprites to the top of img line x of characterSprites - playerSpeed
end repeat
end if
else if k = "down" then
handleWallCollisions
if intersectsBottom = "false" then
repeat with x = 1 to 4
set the bottom of img line x of characterSprites to the bottom of img line x of characterSprites + playerSpeed
end repeat
end if
else if k = "left" then
handleWallCollisions
if intersectsLeft = "false" then
repeat with x = 1 to 4
set the left of img line x of characterSprites to the left of img line x of characterSprites - playerSpeed
end repeat
end if
else if k = "right" then
handleWallCollisions
if intersectsRight = "false" then
repeat with x = 1 to 4
set the right of img line x of characterSprites to the right of img line x of characterSprites + playerSpeed
end repeat
end if
end if
--reset the collision detection
put false into intersectsBottom
put false into intersectsTop
put false into intersectsLeft
put false into intersectsRight
end arrowKey
--notes where the player has intersected to negate the motion of the player into the wall it will be important to start with all intersections set to false
command handleWallCollisions
--for every sprite image
repeat with x = 1 to 4
--for every wall
repeat with y = 1 to numberOfWalls
if intersect (img line x of characterSprites,graphic line y of myWalls, 255) then
repeat with b = 1 to 4
if the bottom of img line b of characterSprites > the top of graphic line y of myWalls then
put "true" into intersectsBottom
end if
if the top of img line b of characterSprites < the bottom of graphic line y of myWalls then
put "true" into intersectsTop
end if
if the left of img line b of characterSprites < the right of graphic line y of myWalls then
put "true" into intersectsLeft
end if
if the right of img line b of characterSprites > the left of graphic line y of myWalls then
put "true" into intersectsRight
end if
end repeat
end if
end repeat
end repeat
end handleWallCollisions