Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
put the image "pUp" into line 1 of myNames
put the image "pDown" into line 2 of myNames
put the image "pLeft" into line 3 of myNames
put the image "pRight" into line 4 of myNames -- = image names
And then got the weird error message:
card id 1002: execution error at line 26 (Chunk: no such object) near "âPNG", char 22
put "pUp" into line 1 of myNames
put "pDown" into line 2 of myNames
put "pLeft" into line 3 of myNames
put "pRight" into line 4 of myNames -- = image names
Still produces the same error message and puts the same thing into myNames.
I made the put "" into myNames addition and nothing changed. Then I did that and changed all instances of the word item to instances of the word line and nothing changed.
I made the put "" into myNames addition and nothing changed.
Do you use "breakpoint"?
I'm pretty sure if you drop a breakpoint in after "put "" into myNames" and look at your variables, myNames will be empty.
Tell me I'm wrong
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
put "" into myNames
breakpoint
put "pUp" into line 1 of myNames
put "pDown" into line 2 of myNames
put "pLeft" into line 3 of myNames
put "pRight" into line 4 of myNames -- = image names
Now I'm just taking a guess at this because I'm not positive about all that is going on but does line j of myRects look something like this;
66,289,576,337
If so... Now you use item
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
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 line x of characterSprites to the top of 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 line x of characterSprites to the bottom of 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 line x of characterSprites to the left of 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 line x of characterSprites to the right of 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
repeat with x = 1 to 4
repeat with y = 1 to numberOfWalls
if intersect (line x of characterSprites, line y of myWalls, 255) then
repeat with b = 1 to 4
if the bottom of line b of characterSprites > the top of line y of myWalls then
put "true" into intersectsBottom
end if
if the top of line b of characterSprites < the bottom of line y of myWalls then
put "true" into intersectsTop
end if
if the left of line b of characterSprites < the right of line y of myWalls then
put "true" into intersectsLeft
end if
if the right of item b of characterSprites > the left of item y of myWalls then
put "true" into intersectsRight
end if
end repeat
end if
end repeat
end repeat
end handleWallCollisions
I don't get any error messages from this one, but for some reason the sprites pass right through the rectangles. Any ideas?