Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
function help
Old
Jake55
Guest
 
Status:
Posts: n/a
Default function help - 03-09-2011, 08:17 AM

i need help with creating a function. how can i create a function that decides true or false on an object i click on.

i have everything else set up, have my "when mouse is clicked on 'anything' do 'method' - 'what was picked'" event.

but i just cant figure out how to relate the click event to my function, and how to get my function to include/exclude certain objects from true/false.

i hope this makes sense to everyone :/.
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 03-09-2011, 11:57 AM

Ok, first. Make a generic click event. It should say "if mouse is clicked on anything, do nothing." Now go to the event that you want it to call. Create a new parameter and make it of type "object." Name it whatever you want, I'll call it "clickedObject" in my example. Now insert method into the event, from the detail panel to the events panel. Drop the method tile in the space called "do nothing" in the events panel. Alice will ask you what you want to set your parameters to. Choose something generic at first like "ground." Now go back to the method in the events panel, and change the parameter by clicking the little arrow, going to "expressions", and clicking "object under mouse cursor." Now, whenever you want to reference the clicked object in your method, just drag the clickedObject parameter tile into your method window. If you want a good example of this, see my game, escape the kitchen, and look at the click event and the method associated with it.

Just follow the link to find the game: http://alice.org/community/showthread.php?t=3597

I hope this helps! =)


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
Jake55
Guest
 
Status:
Posts: n/a
Default 03-09-2011, 06:35 PM

Quote:
Originally Posted by reuben2011 View Post
Ok, first. Make a generic click event. It should say "if mouse is clicked on anything, do nothing." Now go to the event that you want it to call. Create a new parameter and make it of type "object." Name it whatever you want, I'll call it "clickedObject" in my example. Now insert method into the event, from the detail panel to the events panel. Drop the method tile in the space called "do nothing" in the events panel. Alice will ask you what you want to set your parameters to. Choose something generic at first like "ground." Now go back to the method in the events panel, and change the parameter by clicking the little arrow, going to "expressions", and clicking "object under mouse cursor." Now, whenever you want to reference the clicked object in your method, just drag the clickedObject parameter tile into your method window. If you want a good example of this, see my game, escape the kitchen, and look at the click event and the method associated with it.

Just follow the link to find the game: http://alice.org/community/showthread.php?t=3597

I hope this helps! =)
thanks, but im already up to that stage. But i still have the function problem, i need to add a function into the program, and this function must give the rabbit a true or false return for certain objects i click on.
e.g. if i click on a volcano, the function should tell my method false.
but if i click on a flower the function should tell my method its true.

if you want i can upload the file im working on so you can help easier?
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 03-10-2011, 04:10 AM

Quote:
Originally Posted by Jake55 View Post
thanks, but im already up to that stage. But i still have the function problem, i need to add a function into the program, and this function must give the rabbit a true or false return for certain objects i click on.
e.g. if i click on a volcano, the function should tell my method false.
but if i click on a flower the function should tell my method its true.

if you want i can upload the file im working on so you can help easier?
Oh. I see. Like this? (See attachment)
Attached Files
File Type: a2w clickExample.a2w (591.9 KB, 25 views)


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
Jake55
Guest
 
Status:
Posts: n/a
Default 03-10-2011, 05:26 PM

exactly like that!. thanks mate, that was an awesome help
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 03-10-2011, 11:53 PM

Quote:
Originally Posted by Jake55 View Post
exactly like that!. thanks mate, that was an awesome help
No, problem. I prefer using that method because it cleans up the events panel.


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2023, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.