8-puzzle game

Creating Games? Developing something for fun?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Mon Nov 21, 2011 10:14 pm

When creating the actual board of the 8-puzzle game, do the actual 8 tiles have to be dragged and dropped. then each assigned a unique number arranged in a 3 * 3 grid and the shuffle button placed below, the code for which controls the movement of all 8 tiles on the board to be arranged randomly, rather than calling openStack?

Syed

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3305
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Mon Nov 21, 2011 10:20 pm

Hi Syed,

have you looked at the lesson?

Kind regards

Bernd

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Tue Nov 22, 2011 2:16 pm

In the 8 puzzle tutorial, does the shuffle button have to be created manually, then code for it applied to the script for that button?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3305
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Tue Nov 22, 2011 4:18 pm

Hi Syed,

I tried to recreate the 8-piece puzzle from the lesson: http://lessons.runrev.com/s/lessons/m/4 ... zzle-Game-

Unfortunately the assumption of the script that a newly created button is named "new button" is not correct. The name of button created by the "new button" command by script is "button id xxxx". Only a button created by dragging a button from the toolbar is named "new button"

I changed every reference to "new button" to "last button". That works.

I post the working example of the lesson here.
puzzle8piece.livecode.zip
(3.44 KiB) Downloaded 298 times
that should also answer your question: the shuffle button is created when the card gets an openstack message. All buttons are deleted and the game is created anew. To see this type openstack into the message box and hit return.


Kind regards

Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3305
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Tue Nov 22, 2011 4:40 pm

To all,

As of Livecode version 4.6.4 a new button created by script via

Code: Select all

new button
is not named "new button" but "button id xxxx"

That was the reason the script of the lesson for the 8-piece-puzzle failed in Livecode 4.6.4 and later.

Kind regards

Bernd

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: 8-puzzle game

Post by Klaus » Tue Nov 22, 2011 5:16 pm

Hi syedhoque1994,

I highly recommend that you work through these stacks here to get the basics of LiveCode!
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Wed Nov 23, 2011 1:29 pm

I have created the shuffle button and the 8 tiles in the game, but when I run the code and click on either a tile or the shuffle button, there are errors in the script of which seems to be undetectable. Can you find the error in these lines of code?: (put random (sSpaceButton) - 1 into tButtonToSwap) and (put item 1 of location of button ("b" & pButton1) - \).
Thanks

Syed Hoque

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3305
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Wed Nov 23, 2011 3:01 pm

Hi Syed,

in the script of the card replace every occurence of "of me" with "of this stack" if you have the script in the card script.

the three occurences are:

Code: Select all

  set resizable of this stack  to false
end openStack

Code: Select all

set the width of this stack to 60 * sTilesX + sOffset * (sTilesX - 1) + 40

Code: Select all

 set the height of this stack to 60 * sTilesY + sOffset * (sTilesY - 1) + 80
and see if it works if you start the stack anew.

By the way runrev has udated the lesson and it should work now as posted.

Kind regards

Bernd

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Wed Nov 23, 2011 9:47 pm

Thanks for your help Bernd for helping to locate the "of me" code in the card script and replacing it with "of this stack", however I still notice that errors were detected in these lines of code: (put item 1 of location of button ("b" & pButton1) - \) and (put item 1 of location of button ("b" & pButton1) - \), though these lines of code are the same, errors are present when I run the code for any of the tiles and the shuffle button, can you find any such errors here?

Warm thanks

Syed

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3305
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Wed Nov 23, 2011 10:06 pm

Syed,

I append my working version of the puzzle because I don't know why your version is not running. It would help if you would post the code using the Code tab. Especially since this part of code has soft wrapps, this means what seems to be two or more lines of code are actually one. The backslash at the end of the line indicates that the line is continued on the next line.

Try this version and tell us if it works. Don't change anything yet. Only after your have a working version.
puzzle8piece.livecode.zip
(3.46 KiB) Downloaded 257 times
KInd regards

Bernd

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Fri Dec 02, 2011 6:00 pm

My 30 day LiveCode trial has expired and I am now using RevMedia to develop my 8 Puzzle game. When I run the code and click on the Shuffle button, the whole program does not respond and I have to restart my machine and any changes made to the button scripts i.e. the tiles are not saved. Can You inform me of the solution that will get my porgram in working order, so that when I do click the shuffle button, the tiles will move in random areas of the board?

Syed Hoque

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3305
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Sat Dec 03, 2011 6:43 pm

Hi Syed,

I don't own RevMedia and do not know why the stack does not work.

Did you change anything in the code? If so what?

From what I see you should be able to modify code and save it.

Kind regards

Bernd

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Mon Dec 05, 2011 11:07 am

When I click on the shuffle button, the whole program does not respond to any commands that I input and that I have to force quit LiveCode. Is there any solution to this problem to enable the game itself to be in working order?

Syed.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3305
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 8-puzzle game

Post by bn » Mon Dec 05, 2011 11:50 am

Hi Syed,

could you look up what version of Revolution RevMedia has?

I just tested with Revolution version 3 and the stack I posted worked.

I suggest you re-download a fresh copy of the stack I posted above and try again.

Kind regards

Bernd

syedhoque1994
Posts: 25
Joined: Thu Oct 13, 2011 12:13 pm

Re: 8-puzzle game

Post by syedhoque1994 » Mon Dec 05, 2011 1:29 pm

Hi Bernd, just got my 8 Puzzle game in working order, wondering if the game can have a high score table and timer, If so could I please see the code for the score and timer fields?

Syed.

Post Reply

Return to “Creating Games”