Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Subtitles on-off  (Read 6580 times)

0 Members and 1 Guest are viewing this topic.

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Subtitles on-off
« on: October 31, 2004, 07:28:53 PM »

Stupid question: I've been trying to make a subtitles on/off button, but it doesn't work. Any example code?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Subtitles on-off
« Reply #1 on: October 31, 2004, 07:36:20 PM »

Code: [Select]
var BtnSubtitles = this.GetControl("subtitles");

BtnSubtitles.Pressed = Game.Subtitles;
if(BtnSubtitles.Pressed) BtnSubtitles.Text = "X";



////////////////////////////////////////////////////////////////////////////////
on "subtitles"
{
BtnSubtitles.Pressed = !BtnSubtitles.Pressed;
Game.Subtitles = BtnSubtitles.Pressed;
if(BtnSubtitles.Pressed) BtnSubtitles.Text = "X";
else BtnSubtitles.Text = "";
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Re: Subtitles on-off
« Reply #2 on: October 31, 2004, 10:07:01 PM »

Thanks!

Is that saved even when restarting the game? I tried to make one work with registry but without luck.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Subtitles on-off
« Reply #3 on: November 01, 2004, 08:15:58 AM »

Is that saved even when restarting the game? I tried to make one work with registry but without luck.

No, this value is stored in a saved game. If you want to store it in registry, you'll have to use the Game.RegWriteNumber and Game.RegReadNumber methods explicitly.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Re: Subtitles on-off
« Reply #4 on: December 14, 2004, 12:11:37 AM »

Every time the window is opened again the old state of the button is returned and in order to change it you have to click the button twice. Any help?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Subtitles on-off
« Reply #5 on: December 14, 2004, 09:49:17 AM »

I don't see anything wrong with the code above. The first few lines setup the button according to the Game.Subtitles attribute. This code is taken directly from PJ demo so it should work.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Re: Subtitles on-off
« Reply #6 on: December 14, 2004, 05:02:57 PM »

Hmm, will test.
Logged

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Re: Subtitles on-off
« Reply #7 on: December 14, 2004, 05:15:49 PM »

Maybe the button should have some attributes I'm missing? Also, I'm using SetImage instead of just writing "X"...
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Subtitles on-off
« Reply #8 on: December 14, 2004, 05:33:20 PM »

Maybe the button should have some attributes I'm missing?
Hm, can't think of any :( Could you post your code? Or at least the relevant parts?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Re: Subtitles on-off
« Reply #9 on: December 14, 2004, 08:08:15 PM »

options.window

Code: [Select]
BUTTON
{
   IMAGE="sprites\interface\Options\checkbox_on.jpg"
   PARENT_NOTIFY=TRUE
   NAME = "subtitle_btn"

   X = 140
   Y = 192
   WIDTH = 23
   HEIGHT = 17
}

options.script (attached to options.window)
Code: [Select]
#include "scripts\base.inc"
#include "scripts\keys.inc"



var BtnSubtitles = this.GetControl("subtitle_btn");

BtnSubtitles.Pressed = Game.Subtitles;
if(BtnSubtitles.Pressed) BtnSubtitles.SetImage("sprites\interface\Options\checkbox_on.jpg");



////////////////////////////////////////////////////////////////////////////////
on "subtitle_btn"
{
BtnSubtitles.Pressed = !BtnSubtitles.Pressed;
Game.Subtitles = BtnSubtitles.Pressed;
if(BtnSubtitles.Pressed) BtnSubtitles.SetImage("sprites\interface\Options\checkbox_on.jpg");
else BtnSubtitles.SetImage("sprites\interface\Options\checkbox_off.jpg");
}

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Subtitles on-off
« Reply #10 on: December 14, 2004, 09:36:31 PM »

The problem is, that your button is using the checked image by default, while your script only changes the image if the button is (also) checked, it does nothing if it's not checked. So either change the default image to unchecked (in the window definition) or change the script to:

var BtnSubtitles = this.GetControl("subtitle_btn");

BtnSubtitles.Pressed = Game.Subtitles;
if(BtnSubtitles.Pressed) BtnSubtitles.SetImage("sprites\interface\Options\checkbox_on.jpg");
else BtnSubtitles.SetImage("sprites\interface\Options\checkbox_off.jpg");
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Re: Subtitles on-off
« Reply #11 on: December 15, 2004, 01:11:59 AM »

Ah, thanks!
Logged

redfox

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 122
    • View Profile
Re: Subtitles on-off
« Reply #12 on: March 17, 2007, 06:13:53 PM »

Using this method for changing the state of the games Subtitle, what might be the best method to replace the buttons graphics with changing text (such as 'on' and 'off'), with the text taken from the String.tab?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Subtitles on-off
« Reply #13 on: March 18, 2007, 01:05:03 PM »

It would be almost the same, but instead of changing the image, you'd change the text.

Code: WME Script
  1. if(BtnSubtitles.Pressed) BtnSubtitles.Text = Game.ExpandString("/some_id/On");
  2. else BtnSubtitles.Text = Game.ExpandString("/some_other_id/Off");
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

redfox

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 122
    • View Profile
Re: Subtitles on-off
« Reply #14 on: March 19, 2007, 08:25:52 PM »

Excellent, Thanks for your help :)
Logged
 

Page created in 0.041 seconds with 21 queries.