Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 27    Views: 174

Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
10/10/12 07:33 PM (11 years ago)

how to make a button do anything

I've gotten a lot of questions on how I make the "more games" buttons in my apps. I originally used blank screens that loaded ad units. This wasn't really a great method...it just looked kind of weird - the blank screen would load, and then there would be a pause before the ad loaded. I've figured out how to make any button on the menu load anything you want without loading a screen first. I should note that I basically just tweaked the code that was already figured out by David Book and IanJamesPiano in the "Sounds" thread - http://www.buzztouch.com/forum/thread.php?tid=98DD0EB37A4F41E99069E03&status=&searchInput=sounds&sortColumn=FT.dateStampUTC&sortUpDown=DESC¤tPage=1&doViews=1 STEP 1 - Go to BT_Screen_menuButtons.m and scroll down to the section of code that is highlighted in this screenshot - http://bit.ly/VRXyLz STEP 2 - replace the highlighted code from step 1 with the following code (obviously replacing "YOURAPPDELEGATE" with your app delegate, replacing "YOUR ICON NAME" with the name of the button icon, and replacing "YOUR CODE HERE" with whatever action you want the button to take) - //launch screen -(void)launchScreen:(BT_item *)theMenuItem{ //appDelegate YOURAPPDELEGATE *appDelegate = (YOURAPPDELEGATE *)[[UIApplication sharedApplication] delegate]; if([[BT_strings getJsonPropertyValue:theMenuItem.jsonVars:@"imageNameSmallDevice":@""] isEqualToString:@"YOUR ICON NAME"]) { YOUR CODE HERE } else { //get the itemId of the screen to load NSString *loadScreenItemId = [BT_strings getJsonPropertyValue:theMenuItem.jsonVars:@"loadScreenWithItemId":@"0"]; //use the id of the screen we want to load to get it's data object from the app BT_item *screenObjectToLoad = [appDelegate.rootApp getScreenDataByItemId:loadScreenItemId]; //BT_viewControllerManager will launch the next screen [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:theMenuItem:screenObjectToLoad]; } } So basically the above code is assuming that the button your pressing has an icon associated with it. If the icon name of the button you tap is the same as the icon name in the above code, it will not launch a screen...it will instead execute whatever action you put in the "YOUR CODE HERE" area. Any other button you tap will function normally. Since no screen is launching, it doesn't matter what screen the button is associated with. I took a screenshot of an example. In the example I use the button to launch a Chartboost powered "more games" screen. Just for this example the icon name used is "twitter.png" http://bit.ly/TyPOgz hopefully this isn't completely confusing...if anybody needs further clarification feel free to ask
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/10/12 07:48 PM (11 years ago)
Wonderful post. Awesome interview in the buzzcast. Alaska: Sarah Palen...then...@Absentia, @Stobe's gonna make you famous! Ha. If you put this in a PDF I'll add it to the How To's. Great job!
 
AppOne
buzztouch Evangelist
Profile
Posts: 348
Reg: Apr 03, 2012
London
13,980
like
10/10/12 07:55 PM (11 years ago)
You're a clever man, Absentia. I'm going to try this on a bt 2.0 app soon. Do you know how to do the same with tool bar and nav bar icons? ie a location map tool bar?
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
10/10/12 08:06 PM (11 years ago)
@ David Thanks! Pretty high praise coming from the mastermind himself! Glad you enjoyed the interview. I never realized how monotone my voice is haha...kind of makes me sound like I'm bored, but I was totally thrilled to be a part of the buzzcast. I made my girlfriend listen to it and she is now convinced I'm a total nerd. Thats cool with me! I don't know how to make PDF's - I'll look into it and see if I can whip one up @AppOneBeta Not sure..I'll have to look into that as well
 
SheriDee
Code is Art
Profile
Posts: 1094
Reg: Sep 23, 2011
location unknow...
22,840
like
10/10/12 08:06 PM (11 years ago)
Jonathan I really appreciate this! Thanks for taking out the time and helping the community! BTW Loved the interview!!! Keep up the good work!
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
10/10/12 08:24 PM (11 years ago)
@ Sheri No problem. Your soundboard tutorial was actually what inspired this idea!
 
SheriDee
Code is Art
Profile
Posts: 1094
Reg: Sep 23, 2011
location unknow...
22,840
like
10/10/12 08:31 PM (11 years ago)
I did the tutorial after reading forum posts of Raveyd and IanJamesPro and David..... Hey ...got a deal for ya...if you do the pdf I will do the video and then we can send it off to david....or visa versa! I had a one on one with david to get this on 2.0 hosted and have been so busy have not got to it....this will make me accountable! Just let me know! Sheri P.S. PDF Easy How To.....go to google docs ---> Cut paste what you typed----> file--->download as pdf Can edit here: https://docs.google.com/document/d/17RTY9jiDzVV5mURMuwPM1p5uXWDyi5suzqzyVuJinSk/edit
 
SheriDee
Code is Art
Profile
Posts: 1094
Reg: Sep 23, 2011
location unknow...
22,840
like
10/10/12 08:33 PM (11 years ago)
@david do you still have that gomeeting video? I can edit and put it all together if you do. thanks again..
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/10/12 10:01 PM (11 years ago)
@Sheri: Check your email for video info.
 
SheriDee
Code is Art
Profile
Posts: 1094
Reg: Sep 23, 2011
location unknow...
22,840
like
10/10/12 10:10 PM (11 years ago)
@David Opps Too long.... ;)....Thanks again for the time spent Starting on it now! Will let you know when I get done....shouldn't be too bad. Totally motivated now :) Thanks anyway. Sheri
 
SheriDee
Code is Art
Profile
Posts: 1094
Reg: Sep 23, 2011
location unknow...
22,840
like
10/10/12 11:28 PM (11 years ago)
 
buzzbt
Android Fan
Profile
Posts: 233
Reg: Nov 14, 2011
las vegas
6,530
like
10/11/12 10:15 AM (11 years ago)
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
10/11/12 10:29 AM (11 years ago)
Thanks Absentia and buzzbt for this wonderful trick and the pdf.
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
10/11/12 02:19 PM (11 years ago)
didn't even see that PDF buzzbt :( I just got finished making my own and sent it off to David
 
buzzbt
Android Fan
Profile
Posts: 233
Reg: Nov 14, 2011
las vegas
6,530
like
10/11/12 03:17 PM (11 years ago)
Cool it is better wane you do it. b/c you can submit it BT. Thank you for shearing.
 
twotonesimone
Aspiring developer
Profile
Posts: 26
Reg: Sep 01, 2012
Wadhurst
4,060
like
10/12/12 03:03 AM (11 years ago)
just wondered where I find Sheri's soundboard tutorial? I am hoping to make something for my students who dont speak Thanks
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
10/12/12 11:40 AM (11 years ago)
Here's the soundboard tutorial - http://www.buzztouch.com/files/howtos/soundboardTutorial.pdf I also made the tutorial in this thread into a PDF and it's in the How-To section now - http://www.buzztouch.com/files/howtos/make-a-button-do-anything.pdf
 
twotonesimone
Aspiring developer
Profile
Posts: 26
Reg: Sep 01, 2012
Wadhurst
4,060
like
10/13/12 06:45 AM (11 years ago)
Thanks for that Absentia, just a quick question I have glanced through it quickly and all seems fairly easy to implement but I was just wondering if the same code fix will work in Android or is this only likely to work on iOS? It seems BT development of plugins and code is happening quicker in iOS than Android? Thanks
 
SheriDee
Code is Art
Profile
Posts: 1094
Reg: Sep 23, 2011
location unknow...
22,840
like
10/14/12 06:36 PM (11 years ago)
Only tested on IOS. I have heard android a bit tricky to maneuver...it would be a great thing to test. ;)
 
andreatav
I hate code!
Profile
Posts: 5
Reg: Jul 24, 2012
adelaide
2,600
like
11/06/12 02:31 AM (11 years ago)
hey guys, newbie here. how could I just add in my button the function to load / open a hyperlink to a particular website? please advise. thanks Andrea
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/28/13 01:31 AM (11 years ago)
are these instructions ok for BT2.0 ?
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/29/13 12:43 PM (10 years ago)
These are the errors i'm seeing if Absentia or anyone else can shine a light... https://www.dropbox.com/s/4gb2igv8ku0bsqw/Screen%20Shot%202013-04-29%20at%2020.38.56.png
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
04/29/13 04:43 PM (10 years ago)
Yeah the code in this tutorial is a bit outdated - this is the exact same issue that I just mentioned in the other thread. Here is the replacement code that should work for the highlighted errors in that screenshot. Compare this code with the code from your screenshot and you'll get an idea of the differences for future reference ERROR 1 - Replace highlighted code with: if([[BT_strings getJsonPropertyValue:theMenuItem.jsonVars nameOfProperty:@"imageNameSmallDevice" defaultValue:@""] isEqualToString:@"more.png"]) ERROR 2 - Replace highlighted code with: //get the itemId of the screen to load NSString *loadScreenItemId = [BT_strings getJsonPropertyValue:theMenuItem.jsonVars nameOfProperty:@"loadScreenWithItemId" defaultValue:@"0"];
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/29/13 10:45 PM (10 years ago)
so close.... just this line causing issue now //BT_viewControllerManager will launch the next screen [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:theMenuItem:screenObjectToLoad]; with this line, any button pressed causes a crash. With the original line: //BT_viewControllerManager will launch the next screen [BT_viewControllerManager handleTapToLoadScreen:[self screenData] theMenuItemData:theMenuItem theScreenData:screenObjectToLoad]; the buttons work again, but the custom button ignores the code and launches the screen that it was assigned in BTcontrol panel EDIT: its working now. I'd renamed the button image late last night when tired :o) renaming the button correctly and is good. Thankyou
 
mleonard
Apple Fan
Profile
Posts: 124
Reg: Nov 01, 2011
Conway,AR
1,940
like
06/05/13 11:57 PM (10 years ago)
Hey guys, I technically have this working, but am getting a couple of errors saying: Method 'revmobAdDidFailWithError:' in protocol not implemented It's working, but I'm just trying to clean up these errors...any ideas?
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
06/06/13 01:03 AM (10 years ago)
@mienard try adding this at end of the .m file before the dealloc code. - (void)revmobAdDidFailWithError:(NSError *)error { NSLog(@"[RevMob Sample App] Ad failed: %@", error); } Also, it shouldn't be an error only a warning right?
 
mleonard
Apple Fan
Profile
Posts: 124
Reg: Nov 01, 2011
Conway,AR
1,940
like
06/06/13 09:23 AM (10 years ago)
Yes it was just a warning...this worked thanks! I swear I tried this..who knows ha. Also, if I want to add another "if statement" to make a separate button with a different icon name do a different action, do I simply paste another if statement below the current one?
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
06/06/13 09:29 AM (10 years ago)
about the if statement, try it and see how it goes :) if else, if else , end the statement
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.