is this coding right??

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
iphone forever
Posts: 1
Joined: Wed Dec 07, 2011 3:22 am

is this coding right??

Post by iphone forever » Wed Dec 07, 2011 3:25 am

Hi, I am trying to create a game similar to the sheep herding game that was made by Ben. Whenever I try to run this code, it does not work. The game does not start and I don't know whats wrong. Help me please!!


resizeStack
layoutCard
put the width of the stack into tStackwidth
put the height of the stack into tStackheight
set the width of the image "background" to tStackwidth
set the height of the image "background" to tStackheight
set the topleft of the image "background" at (0,0)

on mouseDown
if sGameRunning is true then
put true into sDragging
end if
end mouseDown

on touchMove pId, pX, pY
if the cType of the target is "snowbaLL" and sDragging is true then
set the loc of the target to field "basket"
end if
end touchMove

on touchEnd pId
put false into sDragging
if within(field "basket", the loc of the target) and the cType of the target is "snowbaLL" then
delete the target
scoreIncrement
end if
end touchEnd

on gameInitialize
lock screen
put 0 into sScore
put "x" && sScore into field "score"
put 30 into sTimer
put sTimer into field "time"
put 1 into sLevel
levelClear
unlock screen
end gameInitialize


on scoreIncrement
add 1 to sScore
put "x" && sScore into field "score"
end scoreIncrement

on gameStart
put true into sGameRunning
send "timerPlay" to me in 1 second
end gameStart

on gameStop
put false into sGameRunning
gameInitialize
end gameStop

on timerPlay
if sGameRunning is true then
subtract 1 from sTimer
if sTimer > 0 then
put sTimer into field "time"
send "timerPlay" to me in 1 second
else
put false into sGameRunning
put sScore into field "score"
end if
end if
end timerPlay

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is this coding right??

Post by Mark » Wed Dec 07, 2011 3:35 am

Hi,

First of all, it seems you need to get familiar with the LiveCode language before you start making complete programmes. Try to read more, make small experiments, until you are ready to do some real work.

Second, the gameStart message is never sent. You need to find out when the gameStart handler needs to be called.

Third, it is better to write your scripts from scratch than to copy scripts from one game into a different game, because many things in these scripts won't make sense in your new game and you'll learn most if you write it all by yourself.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: is this coding right??

Post by syedhoque1994 » Mon Dec 12, 2011 11:04 am

In 8 Puzzle, what is the correct coding for the score field for which the user moves tiles, of which one move gains 50 points, a click on the shuffle button loses 25 points and solving the puzzle gains 500 points?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is this coding right??

Post by Mark » Mon Dec 12, 2011 11:55 am

syedhoque1994,

You need to start a new thread, e.g. with title "8 Puzzle score field".

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: is this coding right??

Post by syedhoque1994 » Mon Dec 12, 2011 1:26 pm

I am implementing the 8 Puzzle Score field which will add 50 points to the current score when the user moves a tile, deduct 25 points when the user clicks on the shuffle button and adds 500 points when the user has solved the 8 Puzzle Game.

Is this code for "8 Puzzle Score Field" close to being correct:

on mouseUp
local tScore, tCurrentState
end mouseUp

on UpdateScore
put 0 into "8PuzzleScoreField"
loop = 1 to manhattanDistance
if manhattanDistance is 0 then
tScore = tScore + 50
if ShuffleBoard 10 is 0 then
tScore = tScore - 25
if manhattanDistance (tCurrentState) is 0 then
tScore = tScore +500
end if
next loop
display tScore in "8PuzzleScoreField"
end UpdateScore

If there are any flaws, could you please point them out for me?

Syed.
Last edited by syedhoque1994 on Mon Dec 12, 2011 1:42 pm, edited 2 times in total.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is this coding right??

Post by Mark » Mon Dec 12, 2011 1:37 pm

Syed,

Maybe you don't understand the word "thread"? A thread is a series of replies in a forum starting with a question or statement. So, you need to post a compltely new question, provide a little more info, and then we can answer.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: is this coding right??

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

Hi, I have been told by a friend that the output score field for the 8 Puzzle game has to be referenced to get it to work, what changes should be made to the code?


on mouseUp
// Setup the local variables to be used in this event
local tScore, tCurentState
end mouseUp

command score pScore
put the uScore of this card into tScore
if manhattanDistance (tCurrentState) is 0 then add pScore to tScore else add -pScore to tScore
set uScore of this card to tScore
put format("Futura", tScore) into fld "OutputScoreField" of grp "grpScore"
end score

Syed.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is this coding right??

Post by Mark » Wed Jan 18, 2012 12:19 pm

Syed,

A forum is so much more useful if you know and follow netiquette.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: is this coding right??

Post by syedhoque1994 » Thu Jan 19, 2012 1:24 pm

Yes, I understand netiquette very well on the forum, my main question is how must a score field be referenced to get it to increment,decrement and display scores.

Syed.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is this coding right??

Post by Mark » Thu Jan 19, 2012 1:35 pm

Syed,

No, you have no clue. Otherwise, you would have known where to post your question and you'd have gotten a real answer.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: is this coding right??

Post by FourthWorld » Thu Jan 19, 2012 4:13 pm

Personally, I don't care whether the poster added a question to an existing thread or creates a new one. Sure, it may be optimal to do the latter, but the question is still outstanding and not hard to address, so it seems simpler and more in keeping with the spirit of good netiquette to keep this friendly and just answer it.

Syed, the problem with your code is that the "score" command is never called. You have a mouseUp handler which declares some variables, but does not call the "score" command so that command will never be triggered.

In LiveCode, every action is initiated by events, such as "mouseUp". Some events are user actions, like mouse events, and others are generated by actions like opening a card or a stack (openCard, preOpenCard, openStack, preOpenStack, etc.). Simply defining a command won't invoke it unless you call it from some event handler.

So in the example you posted above, if you call your "score" command in your "mouseUp" handler you should have it triggered and do what you're looking for.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: is this coding right??

Post by Mark » Thu Jan 19, 2012 4:21 pm

Then I'll leave it to you, Richard. I think as a moderator you could move the question to its own thread.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: is this coding right??

Post by FourthWorld » Thu Jan 19, 2012 5:07 pm

Mark wrote:I think as a moderator you could move the question to its own thread.
As a moderator I may be able to, but as a developer I have other things to do so I generally limit my volunteer work here to removing spam (which thankfully hasn't been much of a problem since the forum software upgrade). And as a community member, I'm more interesting in sharing information quickly and easily so we can all use our time productively here.

IMNSHO as much as I love the Ubuntu forums they're way too regulated, with almost as many posts about moving threads and "thread necromancy" as helpful comments. I don't want to be that kind of moderator; I have little use for such strict adherence to what is ultimately an arbitrary adherence to form; I'd much rather just share information quickly and move on with my day.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Games”