Use if(silenceron == false) and if(silenceron == true)
Your checking with a single '=' is incorrect. On Sun, Aug 9, 2009 at 4:37 AM, Hugh <[email protected]> wrote: > > My code is quite simple. When the gunbutton is pressed it should check > that there are bullets left. If so, it should check wether the > silencer is on or off, if its off it should bang and if its on it > should be a quiet bang. If there are no bulelts left it should make a > ammo_out noise. > > It counts ammo correctly but the silencer is always on, despite me > declaring it as off. Please help! > > The code is as follows: > > package hand.gun.app; > > import android.app.Activity; > import android.media.MediaPlayer; > import android.os.Bundle; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.ImageButton; > > > public class HandGunApp extends Activity { > > private int roundsleft = 6; > private MediaPlayer gunreload, gunshot, ammo_out, silencedgunshot; > public boolean silenceron = false; > > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > > ImageButton GunButton = (ImageButton)findViewById > (R.id.GunButton); > gunshot = MediaPlayer.create(this, R.raw.gunshot); > ammo_out = MediaPlayer.create(this, R.raw.ammo_out); > gunreload = MediaPlayer.create(this, R.raw.gunreload); > silencedgunshot = MediaPlayer.create(this, > R.raw.silencedpistol); > > > GunButton.setOnClickListener(new OnClickListener() { > MediaPlayer mp; > @Override > public void onClick(View arg0) { > if (roundsleft <= 0) > { > mp = ammo_out; > mp.seekTo(0); > mp.start(); > } > else > { > if (silenceron = false) > { > mp = gunshot; > mp.seekTo(0); > roundsleft = roundsleft - 1; > mp.start(); > } > else > { > mp = silencedgunshot; > mp.seekTo(0); > roundsleft = roundsleft - 1; > mp.start(); > } > } > ImageButton ReloadButton = (ImageButton)findViewById > (R.id.Reload); > ReloadButton.setOnClickListener(new OnClickListener() { > > @Override > public void onClick(View arg0) > { > roundsleft = 6; > mp = gunreload; > mp.seekTo(0); > mp.start(); > } > }); > ImageButton SilencerButton = (ImageButton)findViewById > (R.id.Silencer); > SilencerButton.setOnClickListener(new OnClickListener() > { > @Override > public void onClick(View arg0) > { > if (silenceron = true) /** If the Silencer is on this > should turn it off */ > { > silenceron = false; > mp = gunreload; > mp.seekTo(0); > mp.start(); > }else{ > silenceron = true; /** If the Silencer is off this > should turn it on */ > mp = gunreload; > mp.seekTo(0); > mp.start(); > } > } > } > > /** Insert other buttons in here */ > > ); > }; > }); > } > } > > > -- Abhiram Alamuru --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

