First Game (help needed)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: First Game (help needed)
Jean-Marc,
Thanks for your explanation of why you use a function. It makes sense if you're going to have many levels one different cards with different items to grab. I will keep this in mind when I work on my game.
--sefro
Thanks for your explanation of why you use a function. It makes sense if you're going to have many levels one different cards with different items to grab. I will keep this in mind when I work on my game.
--sefro
Re: First Game (help needed)
Hi,
I did a same stack with an other way using cds customproperties
Choose the best way is often one difficulty with LiveCode
I can see some handlers move to the stack script
stack script:
cd script
Kind regards
Jean-Marc
I did a same stack with an other way using cds customproperties
Choose the best way is often one difficulty with LiveCode
I can see some handlers move to the stack script
stack script:
Code: Select all
on gCollide
put the uMyObjMove of this cd into tObjMove
put the uMyObjTarget of this cd into tObjTarget
get getAllIntersect(tObjMove,tObjTarget)
if it <> empty then
hide control it
disable control it
end if
if the hilited of control "check" is true then send "gcollide" to me in 2 ticks
end gCollide
on debResetMU
repeat for each item tObj in the uMyObjTarget of this cd
enable control tObj
show control tObj
end repeat
set the loc of control (the uMyObjMove of this cd) to (the uMyLocObjMove of this cd)
end debResetMU
function getAllIntersect pObjMove,pObjTarget
repeat for each item tObj in pObjTarget
if intersect(control pObjMove , control tObj, "pixels" ) then
return tObj
end if
end repeat
end getAllIntersect
Code: Select all
on opencard
initCustomPropCD
debResetMU
if the hilited of control "check" is true then send "gcollide" to this cd in 2 ticks -- solve the start of gcollide
end opencard
on initCustomPropCD
set the uMyObjMove of this cd to "Princess"
set the uMyObjTarget of this cd to "Gem1,Gem2,Gem3"
set the uMyLocObjMove of this cd to 85,319
end initCustomPropCD
Jean-Marc
https://alternatic.ch
-
- Posts: 83
- Joined: Sun Feb 16, 2014 10:08 pm
Re: First Game (help needed)
Well after many trials and errors I ended up with the attached stack which is not perfect but
I am lost now ...
My button "Pr" I wanted to move from center to center of the other buttons if collided with them.
Any clue or guidance is appreciated!
Thanks!
Catalin
I am lost now ...
My button "Pr" I wanted to move from center to center of the other buttons if collided with them.
Any clue or guidance is appreciated!
Thanks!
Catalin
- Attachments
-
- Untitled 1.zip
- (1.92 KiB) Downloaded 353 times
Re: First Game (help needed)
Hi Catalina,
When btn pr collide a btn left,up,right or down it should move from the center of this btn to the center of an other.
If it is which other ?
Kind regards
Jean-Marc
Sorry, I'm not sure I understand correctly what you want.My button "Pr" I wanted to move from center to center of the other buttons if collided with them
When btn pr collide a btn left,up,right or down it should move from the center of this btn to the center of an other.
If it is which other ?
Kind regards
Jean-Marc
https://alternatic.ch
-
- Posts: 83
- Joined: Sun Feb 16, 2014 10:08 pm
Re: First Game (help needed)
Sorry for confusion, let me describe my game mechanics.
I have Princess "button Pr" which needs to move in the direction of the collided button till she collide other
direction button and change the direction accordingly till will collide a STOP button to stop (STOP to be added later)
Yes, she needs to move from a center to a center of a button till she collide the STOP
(The direction buttons will be more than one each in my final game)
Depending the game level I will have more than one directional button for each direction, the player will place the buttons
on a grid so when she collide one she change direction till STOP.
Hope is clearer.
Catalin
I have Princess "button Pr" which needs to move in the direction of the collided button till she collide other
direction button and change the direction accordingly till will collide a STOP button to stop (STOP to be added later)
Yes, she needs to move from a center to a center of a button till she collide the STOP
(The direction buttons will be more than one each in my final game)
Depending the game level I will have more than one directional button for each direction, the player will place the buttons
on a grid so when she collide one she change direction till STOP.
Hope is clearer.
Catalin
-
- Posts: 83
- Joined: Sun Feb 16, 2014 10:08 pm
Re: First Game (help needed)
I played more with the stack and now it works only half a way.
If button Pr is on Right will move to the center of Up and continue upwards
but when it overlaps Left it keeps moving Up.
Same thing if at start the position of Pr is on button Left will move to left and when overlap
Down will go down but then when overlap Right it continue downwards.
Catalin
If button Pr is on Right will move to the center of Up and continue upwards
but when it overlaps Left it keeps moving Up.
Same thing if at start the position of Pr is on button Left will move to left and when overlap
Down will go down but then when overlap Right it continue downwards.
Catalin
- Attachments
-
- Untitled 3.zip
- (1.93 KiB) Downloaded 329 times
Re: First Game (help needed)
Hi Catalin,
You shot yourself in the foot by making the step +- 2
the loc is very specific e.g. buttonLeft is at 613,56 with the +-2 you overshoot it.
Pr can be at 613,55 then next step 613,57... see?
Just changing the step to +- 1 and it all works
Now there are more things for you to work out but I'll leave you with that.
Simon
Edit: It could work with +-2 but you have to make sure the buttons are in the correct locations. For starters try moving button "Left" up 1 pixel.
You shot yourself in the foot by making the step +- 2

the loc is very specific e.g. buttonLeft is at 613,56 with the +-2 you overshoot it.
Pr can be at 613,55 then next step 613,57... see?
Just changing the step to +- 1 and it all works

Now there are more things for you to work out but I'll leave you with that.
Simon
Edit: It could work with +-2 but you have to make sure the buttons are in the correct locations. For starters try moving button "Left" up 1 pixel.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 83
- Joined: Sun Feb 16, 2014 10:08 pm
Re: First Game (help needed)
Hello Simon,
Thanks for the tip, I've overlooked that small "big"detail, now it make sense.
Since I go learning by trial and error visiting the forum searching for clues of how
programming work and getting a lot of inspiration from Mr. Cyril Pruszko web site
tutorials I have related those numbers +/- 2 only to my character speed (I am
at my self now).
As you say, then if I want to increase my character speed by changing the nr. of pixels it moves
at one step then I need to match the coordinates of the "direction" blocks position accordingly.
Regards,
Catalin
PS. How can I "force" LiveCode to stop? some times it goes in some loops and everything blocks
and I do Ctrl+Alt+Del on Win. and force it to stop.
Thanks for the tip, I've overlooked that small "big"detail, now it make sense.
Since I go learning by trial and error visiting the forum searching for clues of how
programming work and getting a lot of inspiration from Mr. Cyril Pruszko web site
tutorials I have related those numbers +/- 2 only to my character speed (I am

As you say, then if I want to increase my character speed by changing the nr. of pixels it moves
at one step then I need to match the coordinates of the "direction" blocks position accordingly.
Regards,
Catalin
PS. How can I "force" LiveCode to stop? some times it goes in some loops and everything blocks
and I do Ctrl+Alt+Del on Win. and force it to stop.
Re: First Game (help needed)
Hi Catalin,
Ctrl + . should stop the process.
But more importantly you need to add this to the stop button code on the card
I think you'll be ok after that. Read up on pendingMessages
Simon
Ctrl + . should stop the process.
But more importantly you need to add this to the stop button code on the card
Code: Select all
--IMPORTANT to stop messages
repeat with x = 1 to the number of lines of the pendingMessages
cancel item 1 of line x the pendingMessages
end repeat
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: First Game (help needed)
Hi Catalin,
Making the character speed 1 may be too slow. 2 worked better. You want to keep the logic separate from the speed of the player.
You were closer to your solution with the previous version. Use the Intersect command, then as soon as they touch, move the player to the center of the block and go from there.
The only problem is as the blocks continue to overlap, you will keep moving the player back to the middle. So you only want to move it the first time they intersect. How can you tell it is the first time?
As soon as they overlap, you highlife the buttonUp (to indicate the change of direction). Use that as part of your test. It is false before that.
Now make much the same changes to your other blocks.
Good job. I see where you are going with your game. That is very creative and I look forward to playing the final version.
You are also doing well learning on your own. keep at it.
Making the character speed 1 may be too slow. 2 worked better. You want to keep the logic separate from the speed of the player.
You were closer to your solution with the previous version. Use the Intersect command, then as soon as they touch, move the player to the center of the block and go from there.
Code: Select all
on buttonUp
if intersect (button "Pr",button "Up") then
set the loc of button "Pr" to the loc of button "Up"
hilite button "markUp"
set the hilited of button "markRight" to false
set the hilited of button "markLeft" to false
set the hilited of button "markDown" to false
end if
end buttonUp
As soon as they overlap, you highlife the buttonUp (to indicate the change of direction). Use that as part of your test. It is false before that.
Code: Select all
on buttonUp
if intersect (button "Pr",button "Up") and not highlighted of button "markUp" then
set the loc of button "Pr" to the loc of button "Up"
hilite button "markUp"
set the hilited of button "markRight" to false
set the hilited of button "markLeft" to false
set the hilited of button "markDown" to false
end if
end buttonUp
Good job. I see where you are going with your game. That is very creative and I look forward to playing the final version.
You are also doing well learning on your own. keep at it.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
- Posts: 83
- Joined: Sun Feb 16, 2014 10:08 pm
Re: First Game (help needed)
Hi Newbie4,
Thanks for your insight and the thumb up.
Well at the very first beginning I used:
and did not worked as intended, now I understand why since you explained.
Yes, definitely I want to keep the speed separated from game logic, in this way I can play
with the player speed according to level or maybe special powers, etc ...
Regards,
Catalin
PS. I am working to replace the "CheckBox" with Variables ...
Noob question now: how LC read the code, it plays the scripts from
TOP to BOTTOM ? if Loops are encountered it keeps them running and
then it moves forward till the end ? so that the first Handler will be processed
and then will process the next Handler under it and so on ...
Thanks for your insight and the thumb up.
Well at the very first beginning I used:
Code: Select all
if intersect (button "Pr",button "Up", "pixels") then
set the loc of button "Pr" to the loc of button "Up"
Yes, definitely I want to keep the speed separated from game logic, in this way I can play
with the player speed according to level or maybe special powers, etc ...
Regards,
Catalin
PS. I am working to replace the "CheckBox" with Variables ...
Noob question now: how LC read the code, it plays the scripts from
TOP to BOTTOM ? if Loops are encountered it keeps them running and
then it moves forward till the end ? so that the first Handler will be processed
and then will process the next Handler under it and so on ...
-
- Posts: 83
- Joined: Sun Feb 16, 2014 10:08 pm
Re: First Game (help needed)
Hello all of you,
here is a very raw, basic, unpolished game in progress I have now.
Well there is a lot of space for improvement and a question:
1) I Copied or Duplicated the direction buttons (bottom right on card) but they would not
work (the button name is the same but obviously the "id" number is different) so
how would I duplicate my buttons for next levels or in the same level and preserve all their functions ?
I think it is something involving "groups"
Play instructions:
place the direction buttons on the path corners then place the Pr button on top of
the first direction button and press Start. Well if everything is fine the Princess will
follow the directions she collide with and will reach the Next Level.
Thanks,
Catalin
here is a very raw, basic, unpolished game in progress I have now.
Well there is a lot of space for improvement and a question:
1) I Copied or Duplicated the direction buttons (bottom right on card) but they would not
work (the button name is the same but obviously the "id" number is different) so
how would I duplicate my buttons for next levels or in the same level and preserve all their functions ?
I think it is something involving "groups"
Play instructions:
place the direction buttons on the path corners then place the Pr button on top of
the first direction button and press Start. Well if everything is fine the Princess will
follow the directions she collide with and will reach the Next Level.
Thanks,
Catalin
- Attachments
-
- Untitled 4.zip
- (2.96 KiB) Downloaded 334 times
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: First Game (help needed)
This concept for this game is awesome. You're doing a great job learning LiveCode, and I look forward to future levels. I'm not sure if you already have graphic assets for your backgrounds and buttons, but I recommend checking out:
http://opengameart.org/
and
http://openclipart.org/
to grab some placeholder images, there's a lot of good stuff between those two sites. Either way, Great Job so far!
--Sefro
http://opengameart.org/
and
http://openclipart.org/
to grab some placeholder images, there's a lot of good stuff between those two sites. Either way, Great Job so far!
--Sefro
-
- Posts: 83
- Joined: Sun Feb 16, 2014 10:08 pm
Re: First Game (help needed)
Thanks Sefro,
I really appreciate your links for graphic assets, I am too exited now that
some of the code is working and I am too hooked in scripting for the moment,
regrading the graphics will be added later.
Question:
on this script where can I put the "repeat" and the "end repeat" so that will do from 1 to 5 to all my direction buttons ?
button "Pr"
I tried the below code but
error (button "Pr": execution error at line 3 (Chunk: no such object) near "Right11", char 25)
I really appreciate your links for graphic assets, I am too exited now that
some of the code is working and I am too hooked in scripting for the moment,
regrading the graphics will be added later.
Question:
on this script where can I put the "repeat" and the "end repeat" so that will do from 1 to 5 to all my direction buttons ?
button "Pr"
Code: Select all
on mouseUp
if intersect (button "Pr", button "Right", "pixels") then
set the loc of button "Pr" to the loc of button "Right"
else
if intersect (button "Pr", button "Left", "pixels") then
set the loc of button "Pr" to the loc of button "Left"
else
if intersect (button "Pr", button "Up", "pixels") then
set the loc of button "Pr" to the loc of button "Up"
else
if intersect (button "Pr", button "Down", "pixels") then
set the loc of button "Pr" to the loc of button "Down"
end if
end if
end if
end if
end mouseUp

Code: Select all
on mouseUp
repeat with x=1 to 5
if intersect (button "Pr", button ("Right1"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Right1"&x)
else
if intersect (button "Pr", button ("Left1"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Left1"&x)
else
if intersect (button "Pr", button ("Up1"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Up1"&x)
else
if intersect (button "Pr", button ("Down1"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Down1"&x)
end if
end if
end if
end if
end repeat
end mouseUp
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: First Game (help needed)
I think it's the "1"'s in your button names in the second example. button ("Right1"&x) will evaluate as "right11","right12","right13", etc..
those buttons don't exist, so it throws an error.
those buttons don't exist, so it throws an error.
Code: Select all
on mouseUp
repeat with x=1 to 5
if intersect (button "Pr", button ("Right"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Right"&x)
else
if intersect (button "Pr", button ("Left"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Left"&x)
else
if intersect (button "Pr", button ("Up"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Up"&x)
else
if intersect (button "Pr", button ("Down"&x), "pixels") then
set the loc of button "Pr" to the loc of button ("Down"&x)
end if
end if
end if
end if
end repeat
end mouseUp