Syntax problem, how is then missing in this statement

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

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

Post by chaucer345 » Fri Aug 08, 2014 12:15 am

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?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Aug 08, 2014 12:36 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

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

Post by chaucer345 » Fri Aug 08, 2014 12:44 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Aug 08, 2014 12:51 am

Try
put "" into myNames
put "pUp" into line....
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Aug 08, 2014 12:54 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

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

Post by chaucer345 » Fri Aug 08, 2014 1:03 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Aug 08, 2014 1:18 am

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!

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

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

Post by chaucer345 » Fri Aug 08, 2014 1:25 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Aug 08, 2014 1:28 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

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

Post by chaucer345 » Fri Aug 08, 2014 1:31 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Aug 08, 2014 1:42 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post by [-hh] » Fri Aug 08, 2014 5:28 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 4:16 pm, edited 1 time in total.
shiftLock happens

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

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

Post by chaucer345 » Fri Aug 08, 2014 8:58 pm

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?

chaucer345
Posts: 23
Joined: Thu Jul 24, 2014 8:08 pm

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

Post by chaucer345 » Fri Aug 08, 2014 10:02 pm

[-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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Aug 08, 2014 11:13 pm

Hi chaucer345,
Can you tell me which objects I should have so I can set up here and run your script?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply