Language Filter

Status
Not open for further replies.

Arcandrus

Villager
Member
Joined
Jan 22, 2016
Messages
11
Reaction score
0
First Language
English
Primarily Uses
So, pretty new to scripting from scratch and am working on something which I think should be simple.


So this part of the script is supposed to set weather or not the language filter is on and display the right message depending;
 

@adult = true


def method_adult()
  case
  when @adult == true
    $game_message.add("Adult language filter on")
    @adult = false
  when @adult == false
    $game_message.add("Adult language filter off")
    @adult = true
  else
    ####
  end
end



This is the test method, which is supposed to show stars instead of the swear word if the language filter is on
 

def methodq()
  string = "Well Frick you!"
    unless @adult == true
      string.gsub!("Frick", "****")
    end
  $game_message.add(string)
end



But for the life of me I cannot get it to function properly... currently the switch changes nothing and the language filter is constantly on.


Can anyone help me out?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,067
Reaction score
6,698
First Language
German
Primarily Uses
RMMV
Both snippets are incomplete, you're not telling us which class you assigned the snippets to and also don't tell us where you call the methods you just defined.


Placing a method definition alone does not execute it, so I think what's happening is that you never called those methods from anywhere.
 

Arcandrus

Villager
Member
Joined
Jan 22, 2016
Messages
11
Reaction score
0
First Language
English
Primarily Uses
My apologies, both of the methods are called by events in the game (screenshot below) but the assignment of class is something I not aware of how to do for something like this

Untitled.png



Also, both are evented as "Script: methodq()" and "Script: method_adult()"
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,067
Reaction score
6,698
First Language
German
Primarily Uses
RMMV
Map screenshots are almost automatically useless - the only case where a map screenshot might help is if you have either a graphical error or if you have problems with a blocked movement.


We need the screenshots of the event pages to see if there is any error.


However, in this case the problem is the missing class assignment - the event command "script" can only execute commands that are accessible to the game_interpreter, all functions outside that (limited) area cannot be used inside a script command.


I suggest you go to the "learn Ruby&RGSS" part of the forum and update your knowledge about classes in Ruby.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
805
First Language
Hungarian
Primarily Uses
RMVXA
Methods made outside of any class/module can be called from anywhere, even in script calls.


Your usage of case statement is wrong, as far as I know.


You should do it this way:


def method_adult
case @adult
when true
$game_message.add("Adult language filter on")
@adult = false
when false
$game_message.add("Adult language filter off")
@adult = true
end
end


But I don't know how instance variables function outside of any class/module. I don't think you can use them like that, but I never tried it, so I can't know for sure.


What you can surely do is to change that instance variable to a global one, and since you already use a switch to toggle the filter ON/OFF, you can use a switch instead.


Example:


def method_adult
case $game_switches[12]
when true
$game_message.add("Adult language filter on")
when false
$game_message.add("Adult language filter off")
end
$game_switches[12] = !$game_switches[12]
end


When you call this method in a script call, it checks switch 12. It displays different message based on the state of switch 12.


After the message, it toggles switch 12 automatically (so, if it was ON before, it will be turned OFF, and if it was OFF before, it will be turned ON).


Similarly, change the '@adult' instance variable in your other snippet to '$game_switches[12]' and it should work.


Of course, you can change the ID of the switch to your preferred one.


But it is a bad practice to make methods outside any classes/modules, so I suggest you move the method into a module at least.
 
Last edited by a moderator:

Arcandrus

Villager
Member
Joined
Jan 22, 2016
Messages
11
Reaction score
0
First Language
English
Primarily Uses
Thank you Sixth! By changing it to a global switch it works exactly as I was hoping it would, and thank you for your insights into scripting, Andar, thank you for directing me towards the Learn Ruby section, found loads of useful information there to :)


Looks like I'm trying to run before I can walk when it comes to my understanding of RGSS lol
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Having lots of fun using different PS brushes to add a lil' texture to the floors and walls in my maps.
Setup a system to cull enemies that are too far from the player to matter, and to spawn new ones just outside of view. Take that lag! :LZSexcite:
That trope is alive more than ever, not so much elemental Crystal's but gathering magical objects or doing "task" to unlock this oddly specific thing is everywhere, I saw it saw it in the IT 2 remake, avengers and every season of supernatural
It's raining...in winter :")

Forum statistics

Threads
93,715
Messages
914,881
Members
123,318
Latest member
Hextasy
Top