on openCard or something else?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
on openCard or something else?
Is on openCard the right thing to use for things happening while the card is open? or is it just used for things that happens when the card opens? Is there something else to use "while" the card is open instead of right when it opens? For example, I am trying to let the player click somewhere and then give them 2 options of what to do after clicking. they need to be able to do this as many times as they want. Should I put this code in on openCard or somewhere else?
-
- VIP Livecode Opensource Backer
- Posts: 9824
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: on openCard or something else?
Clicking generates mouse messages. Try mouseUp.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: on openCard or something else?
Ok. Also, how can I ask the user if he is sure he would like to place an object there or not? Basically, when the user clicks, I want the program to answer by saying "Do you want to place tower?" and give the user the option for yes or no.
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: on openCard or something else?
Check out "grab" it's cooler.
Simon
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: on openCard or something else?
"openCard" is a single message sent to the card when it opens. Period. It can be used for many things, but once sent, whether trapped or not, the card sits idle waiting for something else to happen. It will wait all day if you let it.
Everything else you do derives from new "local" messages, like "mouseUp" as Richard says.
As for your question, (pseudo)
Now I have no idea how you create of move towers around (in other words. what does "makeAndMoveTower" do). Simon believes you might want to grab and drag. That is fine, and will be fun for you to develop. There are other ways, so write back with your thoughts.
Craig
Everything else you do derives from new "local" messages, like "mouseUp" as Richard says.
As for your question, (pseudo)
Code: Select all
answer "Place Tower?" with "yes" or "no"
if it = "yes" then makeAndMoveTower
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9824
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: on openCard or something else?
Seconded. Mouse messages are the way to go here rather than openCard, for the reasons Craig noted. And Simon's suggestion of using drag and drop is a good one for a nicer user experience: if the user is prompted to choose an action each time they click, it makes for a sort of guessing game ("What will happen when I click here?"), but using drag-and-drop to put an object down lets the user perform the action with intent and confidence.Simon wrote:Check out "grab" it's cooler.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: on openCard or something else?
Alright awesome info guys, thank you! I'm going to try this out and do some experimenting and let you know how it works out!
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: on openCard or something else?
So I tried using the grab command and the first tower worked great. the problem is every tower after that. I'm sure it can be fixed with a little code tweaking, I just don't know what needs to be done. Here is what I used:
I used clone because otherwise I would just be dragging the one tower around aimlessly. By cloning it, I can make a new one every time I move it. At least that was the plan. The problem is that I move the original, not the clone. Then every time I try to move it a clone drops by the original, which is placed somewhere else on the screen.
Code: Select all
on MouseDown
clone image "Tower"
grab image "Tower"
end MouseDown
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: on openCard or something else?
Hi Ethan,
I have played around your question using mouse move. Are you sure you want use mousedown to send "makeAndMoveTower" message ?
Here is the result :
Btn script (or what you want)
Card script :
Best regards
Jean-Marc
I have played around your question using mouse move. Are you sure you want use mousedown to send "makeAndMoveTower" message ?
Here is the result :
Btn script (or what you want)
Code: Select all
on mousedown
makeAndMoveTower
end mousedown
Code: Select all
local sMyMoveControlID
on opencard
put empty into sMyMoveControlID
put sMyMoveControlID
end opencard
on makeAndMoveTower
clone control "tower"
set the loc of it to the mouseloc
put "on mouseup;debOneControlMU;end mouseup" into tScript
replace ";" with cr in tScript
put the short id of it into sMyMoveControlID
set the script of control id sMyMoveControlID to tScript
end makeAndMoveTower
on debOneControlMU
put empty into sMyMoveControlID
end debOneControlMU
on mousemove
if sMyMoveControlID <> empty then
set the loc of control ID sMyMoveControlID to the mouseloc
end if
end mousemove
Jean-Marc
https://alternatic.ch
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: on openCard or something else?
I don't understand most of this code....is makeAndMoveTower a user created method? I didn't even know if you could do that in LiveCode or not. I also don't understand most of the code regarding mouseMove....
-
- VIP Livecode Opensource Backer
- Posts: 9824
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: on openCard or something else?
It may be useful to skim some of the User Guide to get a feel for LiveCode scripting.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 327
- Joined: Sun Apr 15, 2012 1:17 am
- Location: USA
- Contact:
Re: on openCard or something else?
You have the right idea. All you need to do is save your location, name your clones something else, then move the original back.
There may be other ways to do it but this seemed the easiest based on the way you started doing it.
Do you understand what each line does and why that line is needed? Look up each command. Make this a learning exercise
Code: Select all
on mouseDown
grab me
put the loc of me into myLoc
clone me
set the name of me to "Tower2"
set the loc of image "Tower" to myLoc
end mouseDown
Do you understand what each line does and why that line is needed? Look up each command. Make this a learning exercise
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: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: on openCard or something else?
wouldn't that only work on the first tower dropped? after that they will not be able to increment from tower2 to tower3 and so on, so it will just screw it all up from there. What about this? I'm getting an error but I think if I can fix whatever is causing the error it should work.
Code: Select all
on MouseDown
clone image "Tower" at location 679, 97
grab image "Tower" --move the tower to desired location. drop when mouse released.
end MouseDown
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: on openCard or something else?
After you have cloned your 'Tower" it might be a good idea to rename it so
you don't end up with lots of objects on your card with the same name:
on mouseUp
clone image "Tower"
set the name of last image to "Tower1"
end mouseUp
Obviously it might be a good idea to keep count by storing numbers in a field:
on mouseUp
clone image "Tower"
add 1 to field "KeepCount"
put "Tower" && fld "KeepCount" into NUNAME
set the name of last image to NUNAME
set the left of image NUNAME to (fld "KeepCount" * 40)
end mouseUp
You will note that I have also added a line ["set the left of . . . ."] to stop the cloned objects piling up on top of each other.
you don't end up with lots of objects on your card with the same name:
on mouseUp
clone image "Tower"
set the name of last image to "Tower1"
end mouseUp
Obviously it might be a good idea to keep count by storing numbers in a field:
on mouseUp
clone image "Tower"
add 1 to field "KeepCount"
put "Tower" && fld "KeepCount" into NUNAME
set the name of last image to NUNAME
set the left of image NUNAME to (fld "KeepCount" * 40)
end mouseUp
You will note that I have also added a line ["set the left of . . . ."] to stop the cloned objects piling up on top of each other.
- Attachments
-
- Cloner.livecode.zip
- Here's my demo stack in case you want to play around with it.
- (2.13 KiB) Downloaded 192 times