8-puzzle game

Creating Games? Developing something for fun?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

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

Re: 8-puzzle game

Post by bn » Mon Dec 05, 2011 1:52 pm

Hi Syed,
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?
I am afraid you are on your own. Livecode is programming, now you would have to try to program timer and high score.
I just wanted to make shure you got a working copy of the 8-puzzle game. From there you start to modify it. But in order to modify it you will have to understand the 8-puzzle game first.

Klaus also posted a link to the conferences. That is an excellent starting point to get into Livecode.

KInd regards

Bernd

Edit:
here is the link to the conferences Klaus mentiioned
http://www.runrev.com/developers/lesson ... nferences/

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

Re: 8-puzzle game

Post by syedhoque1994 » Fri Dec 16, 2011 11:02 am

Hi Bernd,

can you find the error in this line of code: put random (sSpaceButton) - 1 into tButtonToSwap

Syed

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

Re: 8-puzzle game

Post by syedhoque1994 » Wed Jan 11, 2012 12:38 pm

Hi, can you find errors in this line of code?: put the tScore of this card into "OutputScoreField"

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

Re: 8-puzzle game

Post by bn » Wed Jan 11, 2012 1:39 pm

Hi Syde,
put the tScore of this card into "OutputScoreField"
should probably be:

put the tScore of this card into FIELD "OutputScoreField"

you have to indicate what container it is. Except for variables.

Kind regards

Bernd

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

Re: 8-puzzle game

Post by syedhoque1994 » Wed Feb 08, 2012 12:35 pm

I am having a small issue with the 8 Puzzle due to an error in this line of code: put random (sSpaceButton) - 1 into tButtonToSwap
What exactly is this error and which part of the code does it lay?
How can the error be removed so the game can work without any flaws?

kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: 8-puzzle game

Post by kdjanz » Thu Feb 09, 2012 3:41 am

It would help if you would give us the error code information that LiveCode gives you when it breaks on this line. If sSpaceButton is a variable that contains a number for the random() function to use, that should be OK, and if tButtonToSwap is a variable that can receive the new number generated, that should be OK too.

Without seeing the error or more of the code, I can't really help you much more.

Kelly

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

Re: 8-puzzle game

Post by bn » Thu Feb 09, 2012 9:03 am

Hi Syed,

as Kelly said it is difficult to help if you don't provide more info.

As a wild guess:
from the naming of the variable sSpaceButton it sounds as if it is a script local variable. A script local variable has to be declared outside of any handler at the top of the script like this:

Code: Select all

local sSpaceButton -- this declares the script local variable sSpaceButton which then can be used in any handler within the whole script

-- now start start the handlers, for example
on mouseUp
   put 10 into sSpaceButton
end mouseUp

on SomethingElse
   put sSpaceButton into field "myField"
end SomethingElse
Could it be that sSpaceButton is not declared at the top of the script?

Kind regards

Bernd

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

Re: 8-puzzle game

Post by syedhoque1994 » Thu Feb 09, 2012 11:59 am

I am having trouble with the tiles in 8 Puzzle which is the recurring error in all 8 tiles: answer "
You Solved the 8 Puzzle!" with "OK" every time I go in and play the game, could you please help me out to fix this flaw?

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

Re: 8-puzzle game

Post by bn » Thu Feb 09, 2012 12:54 pm

HI Syed,

It would be nice if you would indicate what helped and did not help.

Again just a wild guess: make shure you initialize all script local variables for the main handlers.

Code: Select all

local sOffset, sTilesX, sTilesY, sWinningState, sSpaceButton
in the version of the game I posted this is in the card script at the top.
If sWinningState is not declared as a script local variable then you would see "You solved the 8 Puzzle!"

Please remember: you never said what you changed in the 8 Puzzle game and all I have is the original version to look at:
http://forums.runrev.com/viewtopic.php? ... =45#p45980

Kind regards

Bernd

crazyrock45
Posts: 2
Joined: Wed Mar 14, 2012 4:55 pm

Re: 8-puzzle game

Post by crazyrock45 » Wed Mar 14, 2012 4:58 pm

I am having difficulty with the line put random (sSpaceButton) - 1 into tButtonToSwap
The code was working perfectly until I added a new card. This is not the first time I have run into this error though.
The error message given is thus:
card "card id 1002": execution error at line 161 (random: error in source expression), char 7

please help

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

Re: 8-puzzle game

Post by bn » Wed Mar 14, 2012 5:26 pm

Hi crazyrock,

welcome to the forum.

Could you describe in more detail when the error happens. When you open the stack with the newly created card? Did you change anything in the script of the card with the puzzle?

Kind regards

Bernd

crazyrock45
Posts: 2
Joined: Wed Mar 14, 2012 4:55 pm

Re: 8-puzzle game

Post by crazyrock45 » Wed Mar 14, 2012 10:14 pm

the error message shows when i open the card and click the shuffle button. it does not occur when i click any other button

i changed small things on the card with the puzzle, like the colors of the buttons. but none of these changes had any affect; the stack still ran smoothly after they were implemented. it was only after i added another card that this problem arose. the card is set before the one with the puzzle, and the only programming on it is a button that transfers the user to the card with the puzzle, if that helps

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

Re: 8-puzzle game

Post by bn » Wed Mar 14, 2012 10:53 pm

Hi crazyrock,

the puzzle is constructed on the fly everytime you open the stack. It is triggered by an openStack messages that goes to card 1 of the stack. If you change the order of cards and the puzzle card is no longer card 1 of the stack it will not get the openstack message which should trigger the openStack handler.

use openCard instead of openStack for the first handler of the card script like the code below

Instead of

Code: Select all

on openStack
   # set up the constants for the game type
   setGameConstants 3, 3
   # remove any previous buttons that may already be on the card
   # this prevents us from duplicating existing buttons
   lock screen
   -- more code
end openStack
change that to

Code: Select all

on openCard
   # set up the constants for the game type
   setGameConstants 3, 3
   # remove any previous buttons that may already be on the card
   # this prevents us from duplicating existing buttons
   lock screen
   -- more code
end openCard
that should do the trick if I understand your setup correctly.

Please make shure you don't delete the declaration of the script local variables on top of the card script:

Code: Select all

local sOffset, sTilesX, sTilesY, sWinningState, sSpaceButton
please tell us if this works.

Kind regards

Bernd

Post Reply

Return to “Creating Games”