send mouseUp to button "buttonxy" with random chance

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

send mouseUp to button "buttonxy" with random chance

Post by MarkoSato » Mon May 16, 2016 8:44 am

Hello,

I am trying to implement an old pokemon game with live code. I can attack the enemy but he can't attack me.
I have a button "Attack1" which attacks the enemy and subtracts 45 from his lifebar.
I tried to implement it so, that i have "send mouseUp to button "bossAttack1" in the script of "Attack1". This works. I attack the enemy and then he attacks me back.
Now the thing is, that it is always the same attacks and same order. Therefore I want to implement it so, that when i click my "Attack1" and damage the enemy
the "send mouseUp to button "bossAttack1" should be with a random chance, for example 33,3% and maybe with a 33,3% change to call "bossAttack2" or "bossAttack3".
But I don't know how to implement it that way.
I hope I could describe my problem well and that you can help me.

Best

Mark

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: send mouseUp to button "buttonxy" with random chance

Post by jmburnod » Mon May 16, 2016 9:40 am

Hi Mark,
33,3% change to call "bossAttack2" or "bossAttack3".

Code: Select all

put "bossAttack" & random(3) into tBtn
send "mouseUp" to btn tBtn
Best regards
Jean-Marc
https://alternatic.ch

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: send mouseUp to button "buttonxy" with random chance

Post by MarkoSato » Mon May 16, 2016 1:55 pm

Thank you very much. It works now! you guys are amazing :D

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: send mouseUp to button "buttonxy" with random chance

Post by jmburnod » Mon May 16, 2016 2:03 pm

LiveCode is great :D
https://alternatic.ch

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: send mouseUp to button "buttonxy" with random chance

Post by MarkoSato » Mon May 16, 2016 6:04 pm

Can I ask another question?
Now I have the case that when the boss defeats me, it shows game over and "click to continue"
if i press the continue button I want the same card to start again.
I tried it with "on mouseUp go to card 6 (the card i want to restart)" but it didn't work.
Is there an easy way to restart a card with a button click?

Best regards

Mark

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: send mouseUp to button "buttonxy" with random chance

Post by Klaus » Mon May 16, 2016 6:13 pm

Hi Mark,

how/where does your game start? In an "opencard" script?
If yes put this into your button "Restart":

Code: Select all

on mouseup
  opencard
end mouseup
:D
If you mean something else, please explain.

Best

Klaus

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: send mouseUp to button "buttonxy" with random chance

Post by MarkoSato » Mon May 16, 2016 6:20 pm

Hey,

Dah I am sorry, I just wanted to edit my reply that I found a way but you guys are too fast! :D
Yes I actually tried it with "call preOpencard" and " call openCard" and it worked :oops:
Thank you

Best regards
Mark

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: send mouseUp to button "buttonxy" with random chance

Post by Klaus » Mon May 16, 2016 6:25 pm

No need to "call" the handler, as long as it is in the current "message hierarchy" path*!

* Here a VERY good read about his feature:
http://fourthworld.com/embassy/articles ... _path.html

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: send mouseUp to button "buttonxy" with random chance

Post by MarkoSato » Mon May 16, 2016 6:32 pm

Okay. Thanks a lot

Post Reply