Page 1 of 1
on openCard or something else?
Posted: Sat Mar 05, 2016 6:34 am
by ethanCodes
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?
Re: on openCard or something else?
Posted: Sat Mar 05, 2016 7:27 am
by FourthWorld
Clicking generates mouse messages. Try mouseUp.
Re: on openCard or something else?
Posted: Sat Mar 05, 2016 8:11 am
by ethanCodes
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.
Re: on openCard or something else?
Posted: Sat Mar 05, 2016 8:15 am
by Simon
Check out "grab" it's cooler.
Simon
Re: on openCard or something else?
Posted: Sat Mar 05, 2016 5:13 pm
by dunbarx
"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)
Code: Select all
answer "Place Tower?" with "yes" or "no"
if it = "yes" then makeAndMoveTower
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
Re: on openCard or something else?
Posted: Sat Mar 05, 2016 5:52 pm
by FourthWorld
Simon wrote:Check out "grab" it's cooler.
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.
Re: on openCard or something else?
Posted: Sun Mar 06, 2016 3:18 am
by ethanCodes
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!
Re: on openCard or something else?
Posted: Sun Mar 06, 2016 11:19 pm
by ethanCodes
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:
Code: Select all
on MouseDown
clone image "Tower"
grab image "Tower"
end MouseDown
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.
Re: on openCard or something else?
Posted: Mon Mar 07, 2016 12:28 am
by jmburnod
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)
Code: Select all
on mousedown
makeAndMoveTower
end mousedown
Card script :
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
Best regards
Jean-Marc
Re: on openCard or something else?
Posted: Mon Mar 07, 2016 12:38 am
by ethanCodes
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....
Re: on openCard or something else?
Posted: Mon Mar 07, 2016 3:09 am
by FourthWorld
It may be useful to skim some of the User Guide to get a feel for LiveCode scripting.
Re: on openCard or something else?
Posted: Mon Mar 07, 2016 5:05 am
by Newbie4
You have the right idea. All you need to do is save your location, name your clones something else, then move the original back.
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
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
Re: on openCard or something else?
Posted: Sun Mar 13, 2016 8:06 am
by ethanCodes
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
Re: on openCard or something else?
Posted: Sun Mar 13, 2016 9:21 am
by richmond62
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.

- Cloner.png (8.56 KiB) Viewed 9774 times