Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7638561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:12:14+00:00 2026-05-31T08:12:14+00:00

I am trying to create a simple game. What it should do: Create 2

  • 0

I am trying to create a simple game.

What it should do: Create 2 pushbuttons and when user clicks each button it should disappear.

What it actually does: When I click the first button it disappears. But when I click the 2nd one nothing happens.

clear all, clc, close all

fh = figure;

n = 2;
x = ceil(rand(10)*2);
y = ceil(rand(10)*2);

bgh = uibuttongroup('Parent',fh,'Title',...
    'Button Game','Position',[.1 .2 .8 .6]);

for i = 1:n
    rbh1 = uicontrol(bgh,'Style','Pushbutton','String','Red',...
        'Units','normalized','Position',[rand(1) rand(1) x(1,i) y(1,i)]);
    set(rbh1,'CallBack','set(rbh1,''visible'',''off'')')
end

axt = axes('Parent',bgh,'Units','normalized');

axis([0.5 1 0.5 1])
axis square
axis off

How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:12:16+00:00Added an answer on May 31, 2026 at 8:12 am

    The problem is that you’re setting the callback for one handle only. Change the loop bit of your code to the following and it will work. Since this seems like a learning exercise, I’ll leave it to you to explore it and figure out why making this change helps.

    for i = 1:n
    rbh(i) = uicontrol(bgh,'Style','Pushbutton','String','Red',...
    'Units','normalized','Position',[rand(1) rand(1) x(1,i) y(1,i)]);
    
    set(rbh(i),'CallBack',['set(rbh( ' num2str(i) '),''visible'',''off'')'])
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My friend and I are trying to create a simple RPG style game, in
I'm looking at trying to create a simple 'slider puzzle' game. You've seen the
So I'm trying to create a simple multi-threaded game engine for the game I
I'm trying to create a simple game, but I can't find a certain memory
I'm trying to create a simple game in Pascal. It uses the console. The
I'm trying to create a simple game where the point is to collect as
So I am trying to create a real simple dice game...more like a dice
I am trying to create a simple game wherein a box(alien) is going on
I'm trying to create simple 2D action game, something similar to well known Fancy
I'm trying to create a very simple version of the game Simon with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.