Trouble with Buttons

Old and generally outdated discussions, with the rare hidden gem. Enter at your own risk.

Moderators: Haplo, Lead Developers

Locked
Flawed Spirit
Developer
Posts: 13
Joined: Sun Mar 30, 2008 10:16 pm
Location: If you find out, could you tell me?
Contact:

Trouble with Buttons

Post by Flawed Spirit »

I'm currently working on a mod that involves an option screen with several buttons, but I can't seem to make it work right. Every time I click a button on that screen, it does absolutely nothing.

Below is a quick script I made just to create a couple of basic buttons, with basic responses. Can anyone see what is wrong with this chunk of code just by glancing at it?

Code: Select all

begin FI_test

short button

if ( MenuMode == 1 )
	return
endif

if ( OnActivate == 1 )
	MessageBox "Choose an option.", "Yes", "No"
	set button to GetButtonPressed

	if ( button == 0 )
		MessageBox "You chose yes."
	elseif ( button == 1 )
		MessageBox "You chose no."
	endif
endif

end FI_test
EDITS: Typo in the code, and I fixed the if statements. Buttons start at 0 I think.
MW Interior Modder
Finished MW Interiors: 1
-On a sort of hiatus to work on a solo project.

"Typing with Caps Lock on is for sissies! Holding down Shift is for true heroes!"
Nanu
Developer Emeritus
Posts: 2032
Joined: Thu Feb 16, 2006 12:27 am
Location: Virginia

Post by Nanu »

You don't have anything to handle when the button isn't being pressed. That's -1 IIRC, I haven't scripted for Meht in ages.
"You can remove spells from your list in Morrowind. I think it was shift-click, don't quote me on that though." - Cathartis
|[url=http://tinyurl.com/mnbsqv]Forum Rules[/url]
|[url=http://tinyurl.com/mj594z]Moratorium[/url]
| [url=http://tinyurl.com/6msxag]Writing for TR[/url]
User avatar
Bloodthirsty Crustacean
Developer Emeritus
Posts: 3869
Joined: Fri Feb 02, 2007 7:30 pm
Location: Elsewhere

Post by Bloodthirsty Crustacean »

If in doubt, always scavenge a vanilla script. ;) For buttons, I find the amuletAundae and similar scripts provide a useful template.

But, in this case, I don't need to check to see the problem.

What's happening is that the game is running the second (non-'Menu Mode') block only on the frame that 'OnActivate' holds true, because it's all contained within that if-clause.

What you need to do is move the "if ( button ==" section out of the OnActivate clause, and into one of its own, "if ( messageOn == 1 )". Then, have the OnActivate clause set messageOn to 1.

Finally, have it so that once a button press is recorded, it sets messageOn to 0.

There you go.

If that doesn't make sense, I can provide the script you need.
a man builds a city
with
Banks and Cathedrals
a man melts the sand so he
can see the world outside


"They destroyed Morrowind? Fiddlesticks! Now we're going to have to rebuild it again!"
Flawed Spirit
Developer
Posts: 13
Joined: Sun Mar 30, 2008 10:16 pm
Location: If you find out, could you tell me?
Contact:

Post by Flawed Spirit »

Thanks for the help Bloodthirsty.... do you think you can post that script? I find it hard to visualize stuff having to do with programming.

Thanks.
MW Interior Modder
Finished MW Interiors: 1
-On a sort of hiatus to work on a solo project.

"Typing with Caps Lock on is for sissies! Holding down Shift is for true heroes!"
User avatar
Faalen
Developer
Posts: 312
Joined: Wed Jun 18, 2008 5:22 am
Location: America's Dairyland

Post by Faalen »

Code: Select all

if ( MenuMode == 1 )
     return
endif

if ( OnActivate == 1 )
     MessageBox "Choose an option", "Yes", "No"
     set messageOn to 1
endif

if ( messageOn == 1 )
     set button to GetButtonPressed
     if ( button == -1 )
          return
     elseif ( button == 0 )
          MessageBox "You chose yes"
          set messageOn to 0
          return
     elseif ( button == 1 )
          MessageBox "You chose no"
          set messageOn to 0
          return
     endif
endif
messageOn needs to be declared as a variable. The problem you were originally having is that it takes several frames for a button to return, far more than the one allowed by the script. Also, frames process in MenuMode, so the time it takes the player to select counts.
Q1-77-Tel current progress:
[url=http://tamriel-rebuilt.org/old_forum/viewtopic.php?p=266462#266462]Journals 100% done.[/url]
Practical implementation is now underway.
Flawed Spirit
Developer
Posts: 13
Joined: Sun Mar 30, 2008 10:16 pm
Location: If you find out, could you tell me?
Contact:

Post by Flawed Spirit »

It's so simple when you really look at it. Now that I have this, I think I can expand it to suit my needs. Thanks.
MW Interior Modder
Finished MW Interiors: 1
-On a sort of hiatus to work on a solo project.

"Typing with Caps Lock on is for sissies! Holding down Shift is for true heroes!"
Locked