Page 3 of 4

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 12:15 am
by chaucer345
So I tried -hh's method, but I got a really weird error, maybe it doesn't like the way I initialized myNames?

I initialized myNames as follows in the preOpenCard event:

Code: Select all

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

at this line

Code: Select all

put the left of img (item i of myNames) into x
It appears that my lines are filled with "aPNG" instead of my four images. What happened?

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 12:36 am
by Simon
HI chaucer345,
You actually put the binary information of the images into myNames. :)
I think what you want is ;
put "pUp" into line 1 of myNames

Simon

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 12:44 am
by chaucer345

Code: Select all

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.

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 12:51 am
by Simon
Try
put "" into myNames
put "pUp" into line....

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 12:54 am
by Simon
Oh and

Code: Select all

put the left of img (item i of myNames) into x
In your mind what is an item?
Think about that and see what pops into your head, then give it a try.

more;
Checkout itemDel in the Dictionary, I use it a lot.

Simon

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 1:03 am
by chaucer345
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.

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 1:18 am
by Simon
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

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 1:25 am
by chaucer345
You mean like this?

Code: Select all

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
Nothing changed.

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 1:28 am
by Simon
OK, have to ask something a bit funny...
Are you actually running through that bit of code?
Did the breakpoint trigger?

Yes, you have it in the right place.

Simon

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 1:31 am
by chaucer345
Ah, I noticed that I had to run pre-open card again, sorry : (

Now I have an error at the following:

Code: Select all

if x is within line j of myRects then return true
card id 1002: execution error at line 53 (Operators is: left operand of 'within' is not a point) near "264", char 14

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 1:42 am
by Simon
Hi chaucer345,
You are nearing the point where you should post your stack (you must zip it first).

Code: Select all

if x is within line j of myRects then return true
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

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 5:28 pm
by [-hh]
..........

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 8:58 pm
by chaucer345
In an attempt to unify the various suggestions and test my understanding of what's going on I wrote the following script:

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 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?

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 10:02 pm
by chaucer345
[-hh] wrote:

Here's the script for the card. Hope it works. If not write back.
Hermann
Unfortunately, while the sprite could move, it just got stuck in the wall.

Re: Syntax problem, how is then missing in this statement

Posted: Fri Aug 08, 2014 11:13 pm
by Simon
Hi chaucer345,
Can you tell me which objects I should have so I can set up here and run your script?

Simon