GUI with action-buttons

Started by plebeo, Mon 12/02/2007 01:05:15

Previous topic - Next topic

plebeo

I wanna create a sub-GUI with five button, for a specific room.
When I click to button 1 must compare image 1 and set variable 1,
when I click to button 2 must compare imagine 2 and set variable 2 and etc.

Please Help me giving some instruction!!

thanks guys!!

Ashen

Please, be a bit more specific.

Have you tried anything yet, and if so, what? What are you having trouble with (making the GUI in the first place, or getting it to work right once it is)? What are the 'images' you need to compare? Are they Object graphics, Character graphics (no easy link but this and the Character.View/Loop/Frame properties will find it), the GUI Button graphics, ...
I know what you're thinking ... Don't think that.

plebeo

Ok I try!!

there is this GUI with five buttons.

When I click a button must compare an "object" in the screen and a "variable" must change it's value.
So If I click another button, another "object" must compare and the "variable" must have another value.

I created this GUI and the buttons.

in the script of button 1 I wrote:

#sectionstart button1_Click  // DO NOT EDIT OR REMOVE THIS LINE
function button1_Click(GUIControl *control, MouseButton button) {
variable1 = 1; object1.visible=true; 
}

in the script of button 2:

#sectionstart button2_Click  // DO NOT EDIT OR REMOVE THIS LINE
function button2_Click(GUIControl *control, MouseButton button) {
variable1 = 2; object2.visible=true; 
}

there is another variable (variable2) sets at value 1.

if variable1 = 1  and variable2 = 1 must happens something.

but when I click button1 (that set variable1 at value 1) nothing happens.
It doesn't work and I don't understand why. Where's the error?

I hope is more clear.

Ashen

Unless they're pointers you've made, or psuedocode, object1 and object2 probably won't do anything. The correct usage is object[1], to refer the the object by number, or oObjectname to use the script-o-name (e.g. if you have an object called OBJECT1, it's script-o-name would be oObject1). Also visible should have a capital V - but again this might be a problem here and not in you actual code (I think it'd cause an error, not just do nothing).

What you've got happening there is when you push button1, variable1 is set to 1 and an object is turned on. When you press button2, variable1 is set to 2 (NOTE: not variable2 is set to 1) and another object is turned on. If those objects are already visible, then nothing will appear to happen.
There's nothing that checks anything (values of variables 1 and 2, whatever the images you mentioned are, whether the objects are already visible, etc).

So again, what exactly are you trying to achieve? (Don't worry about the code for now, just try to put what you want to happen, and when.)
I know what you're thinking ... Don't think that.

plebeo

ok I try to explain what I want to do.
There is the player character (a wizard) that enter in a room to fight against another wizard.
Only in this room appear a GUI that represent the book spells of our wizard
Every buttons of the GUI represent a magic formula.
The combinations of two magic formula creates a spell.

For example:
button1 + button2 create spell1

button1 + button3 create spell2

button2 + button3 create spell3

and go on...

Every spell has it's anti spell.

For example:
spell1 destroy spell2

spell2 destroy spell3

spell3 destroy spell1


To destroy the magic spell of enemy wizard (for example spell1), our player must
create spell2 (and to do this he must click button 1 and button 3 of the GUI)

This is the concept, the idea I wanna realize with this sub GUI!!





Ashen

To avoid repeating big chunks of code, I'd recommend making a function that checks the variables ad does the 'spell' if needed. Something like:
Code: ags

function DoSpell() {
  if (variable1 == 1 && variable 2 == 1) {
    //Do spell1 stuff
    variable1 = 0;
    variable2 = 0; // Reset variables for next spell
  }
  else if (variable1 == 1 && variable3  == 1) {
    //Do spell2 stuff
    variable1 = 0;
    variable3 = 0; // Reset variables for next spell
  }
  else if (variable2 == 1 && variable3  == 1) {
    //Do spell3 stuff
    variable2 = 0;
    variable3 = 0; // Reset variables for next spell
  }
  // Etc
}


Then, each of the buttons only has to set the variable and call that function, e.g.:
Code: ags

function button1_Click(GUIControl *control, MouseButton button) {
  variable1 = 1;
  DoSpell();
}


Just be sure that DoSpell comes before the Button functions in the script.

And just to clarify something I said earlier:
Quote
The correct usage is object[1], to refer the the object by number, or oObjectname to use the script-o-name

Since GUI Control functions (like button1_Click, etc) are in the Global Script, you won't be able to use the oObjectname style.
I know what you're thinking ... Don't think that.

plebeo

Really thanks Ashen!!

I try now to insert this scripting code!!!

:D :D

plebeo

I have a little problem with this GUI again!

To win the fiht against the enemy wizard, the player must defeat his spell for three times.

So:

First Time: enemy create spell1, player destroy spell1 with spell3

Second time: enemy create spell2, player destroy spell2 with spell1

Third time: enemy create spell3, player destroy spell3 with spell1.

Only after three time the player wins.

How can I do this with DoSpell() (see above) function???


Thanks




Ashen

Use variables.
You'll need one to store the score (similar to what KhrisMUC showed you in this thread), and one to store what spell the enemy wizard used (if you haven't got this already). The in the spell stuff part of the code, check the enemy's spell against the cast spell - if it's right, do one thing, if not do another:
Code: ags

  if (variable1 == 1 && variable 2 == 1) {
    // Do spell1 stuff
    if (enemyspell == 2) {
      // Do 'You cast the counterspell' stuff'
      score ++;
    }
    else {
      // Do 'You failed' stuff
    }
    variable1 = 0;
    variable2 = 0; // Reset variables for next spell
  }
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk