# Use script as a conditional derivation

#### Arise501

##### Villager Hello group, I am sorry if this does not go here.
I am having a problem, I want to represent Conditional branch math operations, but I don't want to use the event command, I need it inside script.
JavaScript:
``if (origen_y < 0) {origen_y * (-1)};``
Is this the correct way to write?
If "variable" <0, multiply "variable" * (- 1)
This is what I'm trying to do, but I don't know much about code.
RMMV Script Calls
I use the information here.
Conditional branch/ if (code) {stuff} plus {stuff}
But I don't know how to fill in "code" and "stuff"

#### Shaz

##### Veteran Close.

origen_y *= -1

#### Arise501

##### Villager #### Kuro DCupu

##### Trust me, I'm a veteran RMer `\$gameVariables.value(ID)` is "read only".
If you want to change the value, it should be: `\$gameVariables.setValue(ID, NEW_VALUE)`

So it will be:
`if (\$gameVariables.value(170) < 0) { \$gameVariables.setValue(170, \$gameVariables.value(170) * -1) }`

----

Anyway, it seems your purpose is to not allow negative value.
In that case, you should have used `Math.abs` instead, as it returns "absolute" value:
`\$gameVariables.setValue(170, Math.abs(\$gameVariables.value(170)))`

Thus you don't need "if" condition.

Even more, your event in the screenshot could be further shortened like this: Last edited:
• Shaz and Arise501

#### Arise501

##### Villager `\$gameVariables.value(ID)` is "read only".
If you want to change the value, it should be: `\$gameVariables.setValue(ID, NEW_VALUE)`

So it will be:
`if (\$gameVariables.value(170) < 0) { \$gameVariables.setValue(170, \$gameVariables.value(170) * -1) }`

----

Anyway, it seems your purpose is to not allow negative value.
In that case, you should have used `Math.abs` instead, as it returns "absolute" value:
`\$gameVariables.setValue(170, Math.abs(\$gameVariables.value(170)))`

Thus you don't need "if" condition.

Even more, your event in the screenshot could be further shortened like this:
View attachment 150825
Now I understand, of course it was a variable control, I was not seeing it well.
The script is more complex, that was only a summary, the objective that always has a positive number. It is for a pan sound scrip.
Thanks for helping me, I am just learning javascript, I know that these things are very basic, but it is still difficult for me to be aware of everything. You have helped me a lot.

JavaScript:
``if (origen_y < 0) {Math.abs(origen_y)};``
So with the first example, would it be this way?
I want it to be a positive number.

Last edited:

#### Shaz

##### Veteran You're using a mix of pure script, and Control Variables.

If you have a Variable that you have named origen_y, you don't actually refer to it as origen_y anywhere. You always refer to it using the variable ID.

You can do one of these:

Code:
``````If Variable 170 < 0
Control Variables 170 *= -1``````
or without a conditional branch:
Code:
``Control Variables 170 = Script: Math.abs(\$gameVariables.value(170))``
or
Code:
``Script: \$gameVariables.setValue(170) = Math.abs(\$gameVariables.value(170));``

If this is confusing, please put in what you think should be right, and then take a screenshot of that window, so we can see where and how you're trying to use it, and not just the syntax, because the syntax needs to be correct for where and how you're entering it.

#### Arise501

##### Villager You're using a mix of pure script, and Control Variables.

If you have a Variable that you have named origen_y, you don't actually refer to it as origen_y anywhere. You always refer to it using the variable ID.

You can do one of these:

Code:
``````If Variable 170 < 0
Control Variables 170 *= -1``````
or without a conditional branch:
Code:
``Control Variables 170 = Script: Math.abs(\$gameVariables.value(170))``
or
Code:
``Script: \$gameVariables.setValue(170) = Math.abs(\$gameVariables.value(170));``

If this is confusing, please put in what you think should be right, and then take a screenshot of that window, so we can see where and how you're trying to use it, and not just the syntax, because the syntax needs to be correct for where and how you're entering it.
JavaScript:
``````var VolumenMax   = 50;
var DistanciaMax = 15;
var falloff = VolumenMax / DistanciaMax;
var origen_x    = \$gameMap.event(6).x;
var origen_y    = \$gameMap.event(6).y;
var se = {"name": "Bell1", "pitch": 70};
var pan = \$gamePlayer.x - origen_x;
se.pan = (pan * -9);
if (origen_x < 0) {Math.abs(origen_x)};
var pow_x = (origen_x - \$gamePlayer.x) * (origen_x - \$gamePlayer.x);
var pow_y = (origen_y - \$gamePlayer.y) * (origen_y - \$gamePlayer.y);
var realDistance = Math.sqrt(pow_x + pow_y);
se.volume = VolumenMax - falloff * realDistance, 0 ;
AudioManager.playSe(se);``````
It is a panning sound script.
I use a variable and I needed it to be positive at some point.
I did the tests and it worked fine.
Creo que todo ya está resuelto.
JavaScript:
``if (origen_x < 0) {Math.abs(origen_x)};``
This was the part I didn't understand before.

#### Shaz

##### Veteran Okay, you can leave out the if part and just make that line

origen_x = Math.abs(origen_x);

However, my original answer should have worked:

if (origen_x < 0) {origen_x *= -1};

#### Arise501

##### Villager I understand, and I'm sorry, maybe I wrote incorrectly, when I copied what you wrote, I got an error. But I am new to javascrip, maybe the error was mine.
It is my first script command, thanks for your help.

Sorry, I don't know how to delete this message.

#### Arise501

##### Villager Okay, you can leave out the if part and just make that line

origen_x = Math.abs(origen_x);

However, my original answer should have worked:

if (origen_x < 0) {origen_x *= -1};
I understand, and I'm sorry, maybe I wrote incorrectly, when I copied what you wrote, I got an error. But I am new to javascrip, maybe the error was mine.
It is my first script command, thanks for your help.

#### Shaz

##### Veteran We can't delete messages. You could report the post and ask a mod to delete or hide it if you want.

Is the issue solved - is it all working for you now?

#### Arise501

##### Villager If it works, turn the volume up and down, and panning works. Thank you very much.

### Latest Profile Posts

I'm so amazed at this ABS plugin for MV. This is a plugin that can literally fulfill my biggest game dreams, creating an Ultima VII-like game. Below is a video of a quick scenario I created to test out the plugin. The music in the video is my own composition.

The MZ Steam discussion board is filled with so much whining. Glad I never have to go there, or to any Steam discussion board. Anyway, here's something awesome:
I've been meaning to create a better trailer for my game but it takes time, so for now all I got is the same old trailer with updated footage:

I spoke with hudell and many programmer about the Window_BattleLog class and we all just agreed to pretend this class just doesn't exists lol
{"ft_lang_label":"__label__en","ft_lang_prob":0.8966332,"math_prob":0.5372738,"size":1144,"snap":"2020-34-2020-40","text_gpt3_token_len":317,"char_repetition_ratio":0.1,"word_repetition_ratio":0.68599033,"special_character_ratio":0.2805944,"punctuation_ratio":0.10958904,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9536069,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-10T10:30:10Z\",\"WARC-Record-ID\":\"<urn:uuid:9282d1eb-b241-49b8-ae87-d398d4df1cdf>\",\"Content-Length\":\"131632\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b61eec9c-07ec-40eb-94bf-cbf4dca30c9b>\",\"WARC-Concurrent-To\":\"<urn:uuid:b48a7392-65de-49c0-b6c6-27ead2bd44b2>\",\"WARC-IP-Address\":\"45.79.217.141\",\"WARC-Target-URI\":\"https://forums.rpgmakerweb.com/index.php?threads/use-script-as-a-conditional-derivation.123870/\",\"WARC-Payload-Digest\":\"sha1:O2ITWRPFKASEEIYKYFRXNV5LWUZJGQMI\",\"WARC-Block-Digest\":\"sha1:67BZZN26MELKADOBOCW6LKFV4JG24KQF\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439738674.42_warc_CC-MAIN-20200810102345-20200810132345-00435.warc.gz\"}"}