how to subtract the move of a player

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kesh17aki
Posts: 12
Joined: Sat Jan 19, 2013 4:05 am

how to subtract the move of a player

Post by kesh17aki » Sat Jan 26, 2013 2:17 am

im having a problem regarding on how to make the player move back. i have a gameboard for snake and ladders. and i only have 36 grids. each grids has a specific location. my problem is when the player reaches to the last line of the grid. w/c means the player reaches the last line of the grid. when the dice stops at 4,5,or 6 and it would be the number of dice stopped > 36, the player should move backward regarding the number of dice given. i have here the code , at the first condition, it works but when it tried to move n the same condition, the player goes down to the first line of the grid. i dont know what is wrong but i really need help for this . here's the code

Code: Select all

on movePone
    
   --numdice1 refers to the current number of box location
   --sdice referes to the number of dice
   put (numdice1+sdice) into sdice
   
  
   put setofLocations(sdice) into pMoveOneLoc
   getTheLocation "plyrOne"
   if sdice > 36 then
      put (36-sdice) into sdice
      put setofLocations(sdice) into pMoveOneLoc
      move btn "plyrOne" from theCurrentLocation to pMoveOneLoc in 100 ticks
       
   else 
   
      move btn "plyrOne" from theCurrentLocation to pMoveOneLoc in 100 ticks
  
   end if
   put sdice into numdice1
  
end movePone


on getTheLocation theplayer
   put the location of btn theplayer into theCurrentLocation
end getTheLocation


function setofLocations thesum
   put "1-458,681*2-554,681*3-651,681*4-748,681*5-842,681*6-932,673*7-931,567*8-841,558*9-747,558*10-650,558*11-553,558*12-458,552*13-458,446*14-553,441*15-650,441*16-749,440*17-842,440*18-932,443*19-932,328*20-841,321*21-748,322*22-650,322*23-554,322*24-458,315*25-458,207*26-553,201*27-650,201*28-748,201*29-842,202*30-932,194*31-932,81*32-842,74*33-748,74*34-651,74*35-553,74*36-458,76" into locationlist
   
   set the itemDel to "*"
   
   
   put the item thesum of locationlist into holder
   
   set the itemDel to "-"
   
   return the item 2 of holder
   
end setofLocations

on getTheLocation theplayer
   put the location of btn theplayer into theCurrentLocation
end getTheLocation



dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Location: Thailand
Contact:

Re: how to subtract the move of a player

Post by dave_probertGA6e24 » Sat Jan 26, 2013 8:50 am

Hi,

Without really understanding what the program is doing or what the problem is, I can see a couple of errors in the code.

Code: Select all

set the itemDel to "*"
put the item thesum of locationlist into holder
set the itemDel to "-"
return the item 2 of holder
The above code has too many uses of 'the' before 'item' - try changing it to this:

Code: Select all

set the itemDel to "*"
put item thesum of locationlist into holder
set the itemDel to "-"
return item 2 of holder
The use of 'the' usually refers to a property of a thing, whereas 'item n of' is a 'chunk' offset into a list. You will have to read more on the properties and chunk stuff in the user guides.

I hope that helps a bit,

Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

kesh17aki
Posts: 12
Joined: Sat Jan 19, 2013 4:05 am

Re: how to subtract the move of a player

Post by kesh17aki » Tue Jan 29, 2013 4:14 am

thanks for the help. now i got it all working :) now i know what's the difference when putting "the" in item and the item alone :)

Post Reply

Return to “Games”