Script Calls

AriArk

Villager
Member
Joined
Jul 12, 2013
Messages
25
Reaction score
0
First Language
English
Primarily Uses
Hello,

I am trying to make simple script calls.

First of all, I want a script call that sets a Boolean to true or false

Second, I want to make a script call that sets a Variable to a integer or string.

Thanks for any help.
 

djDarkX

Retro & Remastered Music Guru
Veteran
Joined
Jan 17, 2013
Messages
2,700
Reaction score
1,901
First Language
Music
Primarily Uses
RMMV
I believe variables that can be controlled via the event commands cannot hold strings, just integers.  If so, that would be $game_variables[n] == n.  As for the Boolean, I assume you'd be using is a switch, which would be $game_switches[n] == true/false (toggled on or off).

Either way, check my sig for event command script call equivalents.  It may help you better than I can with the information I have off the top of my head. lol
 

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
Code:
$game_variables[id] = "Whatever you want to assign it to."
As for setting a boolean to true or false, I'm not entirely sure what you mean -- but in Ruby, you cannot change a TrueClass or FalseClass directly. For example, you can't execute true = false. You'll receive a "can't assign to true" syntax error. If you're wanting to toggle a switch with a script call, that's simple.

Code:
$game_switches[id] = !$game_switches[id]
Edit: Just to clarify, you can set a game variable to anything you want in a script call (as long as the assignment is legal, obviously), they don't have to be integers (as djDarkX assumed -- which is a logical assumption, but not technically correct).
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
You have to provide more information about what you really want to do with the result.


For example do you want to set a game switch to true/false (checked in events as ON/OFF) or do you want to define a new boolean variable to set? In the last case, how do you want to use that variable as you don't have event access to new variables but need to use other script calls to check that?


The same questions apply to the second part - the game variables are predefined for access in events, new variables are not, and storing a string into a game variable is theoretically possible, but you'll risk errors and crashes if you aren't very careful. Better to store strings into new variables.


And that goes to the next problem: are you asking about script calls (with the event command script) or are you talking about real scripts (in the script editor)? If you aren't carefull with the definition of new variables, they will be deleted by the internal garbage handling as soon as the script call is completed.


Scripting is a full programming language in RM - what other game engines usually call scripting is called eventing here.
 

djDarkX

Retro & Remastered Music Guru
Veteran
Joined
Jan 17, 2013
Messages
2,700
Reaction score
1,901
First Language
Music
Primarily Uses
RMMV
Thanks for the correction Solistra.  I'll pack that bit of information away for later. lol
 

AriArk

Villager
Member
Joined
Jul 12, 2013
Messages
25
Reaction score
0
First Language
English
Primarily Uses
It's not game variables, I know how to change them. See, I have this in a script I'm making:

@show_party_characters = trueI want to be able to change that to false through a script call.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
It's not game variables, I know how to change them. See, I have this in a script I'm making:

@show_party_characters = trueI want to be able to change that to false through a script call.
Then simply write
Code:
$show_party_characters = false
into a script command.If that "$show..." is public and writable, then that is enough.

If you defined that as private or read-only, then you need to redefine it in your script, but you don't need any special calls for it.
 

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
It's not game variables, I know how to change them. See, I have this in a script I'm making:

@show_party_characters = trueI want to be able to change that to false through a script call.
You're not giving us enough context. We don't know what class that instance variable is defined in. As a general rule, however, changing instance variables on a specified instance is relatively simple: add an attr_accessor or attr_writer keyword to the class, and the instance variable can be assigned to through a generated method.

class Example attr_accessor :message def initialize(message = 'Hello, world.') @message = message endendexample = Example.newexample.message = 'Like this.'puts example.message # => "Like this."Adding an accessor automatically creates reader and writer methods for the instance variables sent to the keyword you used (remember to use symbols as arguments to the keyword). If you have an accessor for the above example, it would generate Example#message and Example#message= methods for you which reference the appropriate instance variable.Also, in response to Andar's reply, global variables are always public and writeable -- that's the point, they're global. You can't create a private global variable. With that said, instance variables also don't automatically generate global variables, so $show_party_characters would evaluate to nil unless that global variable was defined -- the example AriArk presented was an instance variable.

Edit for the pedantic: Technically, the attr_* 'keywords' are actually methods, not proper Ruby keywords. Regardless, they're used as keywords (much like a number of other Ruby methods), and I think it's generally less confusing to refer to them as such.
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top