Newbie js question

hainsay

Villager
Member
Joined
Dec 2, 2013
Messages
25
Reaction score
7
First Language
English
Primarily Uses
I've been trying to get something to work, while learning js in parallel, but it seems (to me) that I am missing some syntax particular to RM, so I thought I'd just come out and ask.

I need

if( (variable1 mod (2^(variable2)) < 2^(variable2 - 1)) {} which is obviously too complex for the non-script conditional branch options.

I understand I need to use

$gameVariables

and while I can see on the script calls spreadsheet I can change a variable by using $gameVariables.setValue(var,value);

I have no idea how to "getValue". How do you use a variable value within a script?

Please indulge my question, I'm not sure whether I'm missing something from a js perspective, but the only instance of $gameVariables I can find is in DataManager and that doesn't declare the data type, so I'm a bit stuck, especially if there is syntax specific to RM (which I am too newbie to know for sure).
 

hainsay

Villager
Member
Joined
Dec 2, 2013
Messages
25
Reaction score
7
First Language
English
Primarily Uses
Oh I figured it out. I was using the value function with a capital letter.

I had

if( $gameVariables.Value(1) % 2^($gameVariables.Value(2)) < 2^($gameVariables.Value(2) - 1) {}

instead of

if( $gameVariables.value(1) % 2^($gameVariables.value(2)) < 2^($gameVariables.value(2) - 1) {}

Nothing like posting a question for making an epiphany.

Thread can be closed, thanks.
 

johanes

Hobo
Veteran
Joined
Oct 13, 2016
Messages
97
Reaction score
9
First Language
Filipino
Primarily Uses
N/A
just a question, what is the "%" for???
 

hainsay

Villager
Member
Joined
Dec 2, 2013
Messages
25
Reaction score
7
First Language
English
Primarily Uses
just a question, what is the "%" for???
First a disclaimer, I am new to javascript so I don't know whether it works. However, % should be a modulus operation. I haven't seen what I've done on here before, but essentially what I'm doing is using one variable to represent many variables or "game progression states".

I'll say first that I've since discovered that I could use an array to do this more simply so you won't learn anything useful by reading what I was trying to do, but what I had worked out went like this:

I identify some event as being likely the nth you will encounter in the story, so it with be associated with the id n

variable2 == n // variable2 is a single use variable that I just use for this event but can be reused for any similar calculation
if ( variable1 mod (2^variable2) < (2^(variable2-1)) //Is it true that I haven't run this event before?
then
run event
variable1 += 2^(variable2 -1) //Record in variable1 that I have run the event with id n
end;
Erase Event //enables event page 2 that is the inactive state



Basically, in hindsight, I created an extra variable to keep track of which events had run when I could have just used a self switch. However, I had in mind that variable1 would keep track of all game progress, such as if you had a town that you could upgrade, which would change tilesets on the map or create events representing houses and stuff. Probably easier with an array if you are using it for such a dedicated purpose though.

Ah well, I'm learning.



Edit: Oh, as far as what you could use the mod function for, suppose you have 40 collectibles in a game, and you get a bonus every 5 collectibles, and an npc manages that.

Then asking the npc for the bonus would be something like

if collectiblesCount > 5*(currentRewardLevel +1)
then give reward, currentRewardLevel += 1
else show text : you need /(5 - collectiblesCount % 5) more collectibles for a reward

(Don't for a minute think my syntax is right)
 
Last edited:

johanes

Hobo
Veteran
Joined
Oct 13, 2016
Messages
97
Reaction score
9
First Language
Filipino
Primarily Uses
N/A
im just asking what ("%") this is:kaoangry:
turns out to be a remainder function, if im using it wrong....
,went through the internet to find what this is, but found non, so i used it... still doesnt know its real function
 

hainsay

Villager
Member
Joined
Dec 2, 2013
Messages
25
Reaction score
7
First Language
English
Primarily Uses
yeah it is. known as the modulus operation.
 

johanes

Hobo
Veteran
Joined
Oct 13, 2016
Messages
97
Reaction score
9
First Language
Filipino
Primarily Uses
N/A
thanks .... for the term,
modulus operation
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
yeah it is. known as the modulus operation.

$gameVariables.value(num); // to get value
Code:
var G = $gameVariables; // ref
var v1 = G.value(1); // call $gameVariables.value(1)
var v2 = G.value(2);
var v3 = G.value(3);

if ( (v1 % (2^(v2)) < 2^(v2 - 1)) {
    //code
}

is here when mouse hover description [c] Colone
 
Last edited:

hainsay

Villager
Member
Joined
Dec 2, 2013
Messages
25
Reaction score
7
First Language
English
Primarily Uses
waow. Thanks, I didn't know about the quotes. This will make things so much easier.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
waow. Thanks, I didn't know about the quotes. This will make things so much easier.
you can also use the console log to find what you need in all object.
Ex: to find any function in $gameVariables
tape $gameVariables in the console Debug (F8)
And find function you need.
asegaegae.jpg
 

mogwai

1984
Veteran
Joined
Jun 10, 2014
Messages
876
Reaction score
581
First Language
English
Primarily Uses
RMMV
I just learned in December that any changes you make to a variable that equals the value of an array or an object, change said array or object, but changes to a variable equal of a string or integer do not change the owning string or integer.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
I just learned in December that any changes you make to a variable that equals the value of an array or an object, change said array or object, but changes to a variable equal of a string or integer do not change the owning string or integer.
ya me too, I learned this recently.
Ideally, you must think about it, because its can be source of very big problems.

Code:
this.MENUxy = [120, 330];
this.d8a757 = [this.MENUxy[0],this.MENUxy[1]];
// the memory ref block are not same, so you can change this.d8a757, will not afect this.MENUxy

// but if
this.MENUxy = [120, 330];
this.d8a757 = this.MENUxy;
// the memory block are same, all change in this.d8a757 will afect this.MENUxy in same time

// you can also create a function to return
this.MENUxy = [120, 330];
this.getMENUxy = function(){return this.MENUxy}
this.d8a757 = this.getMENUxy();
// the memory ref block are not same, so you can change this.d8a757, will not afect this.MENUxy
 

mogwai

1984
Veteran
Joined
Jun 10, 2014
Messages
876
Reaction score
581
First Language
English
Primarily Uses
RMMV
Too much Greek for me.

Modulus has a cool ring to it. I've been calling it remainder for the longest time.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
Too much Greek for me.

Modulus has a cool ring to it. I've been calling it remainder for the longest time.
i very love use the math modulus% when i need to do a loop with For(){}
it very easy to make distance between thing.
I study them in depth to understand all its usefulness and performance
ex: here my code to show my HUD, with perfect distance

Code:
    for (var I=0,C=0,R=0;I<6;I++,R++){ // small states
        $image.ease1(PID++, {_x:this.ee0e17[0]+(this.DSsxy[0]*C) ,_y:this.ee0e17[1]+(this.DSsxy[1]*R)},'back','inOut',duration,0); //#ee0e17 BG STATES LARGE
        $image.ease1(PID++, {_x:this.f0ff17[0]+(this.DSsxy[0]*C) ,_y:this.f0ff17[1]+(this.DSsxy[1]*R)},'back','inOut',duration,0); //#f0ff17 STATES ICONS SMALL
        $image.ease1(PID++, {_x:this.f44141[0]+(this.DSsxy[0]*C) ,_y:this.f44141[1]+(this.DSsxy[1]*R)},'back','inOut',duration,0); //#f44141 PIXITEXT STATES ATT,DEF,LUK...
        if (I%2 === 1){R=-1,C++;} };
    }
this give to me pefect easy menu loop distance
aefa-modulus.jpg
 

mogwai

1984
Veteran
Joined
Jun 10, 2014
Messages
876
Reaction score
581
First Language
English
Primarily Uses
RMMV
total distance between things could be like
PHP:
Math.hypot(x1-x2,y1-y2);
Or for ease in between from speed...
PHP:
var angle = Math.atan2(y1 - y2, x1 - x2);
var x3 = Math.cos(angle) * speed;
var y3 = Math.sin(angle) * speed;
Forgive me if what you are writing is a hightech 3D thing.
I just googled Head's Up Display. The only HUD I know is my apartement
That looks like hex colors. You do know about context.createLinearGradient() right?
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
total distance between things could be like
PHP:
Math.hypot(x1-x2,y1-y2);
Or for ease in between from speed...
PHP:
var angle = Math.atan2(y1 - y2, x1 - x2);
var x3 = Math.cos(angle) * speed;
var y3 = Math.sin(angle) * speed;
Forgive me if what you are writing is a hightech 3D thing.
I just googled Head's Up Display. The only HUD I know is my apartement
That looks like hex colors. You do know about context.createLinearGradient() right?
I understand, there are multitude of ways of doing.
It's always interesting to see how other work.
Modulus%, it one interessence way,among other.

Sorry for the hex codes, it is only for my visual reference in my codes.
These are a new tips that I try, for make specific references easy to visualize, especially if your plug + fon 500 line.
Eyes will catch more fast visual color than grey text
This helps me a lot if I have a function that affects certain object that is the same reference object.

Ex:
fhjabjanbfjad.jpg

.
 

mogwai

1984
Veteran
Joined
Jun 10, 2014
Messages
876
Reaction score
581
First Language
English
Primarily Uses
RMMV
What is XOR ^ by the way?

On a graphic calculator that symbol is pow. I'm all mixed up.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
What is XOR ^ by the way?

On a graphic calculator that symbol is pow. I'm all mixed up.
XOR is for get Binairy ref of a number hex base.
This is the basic quantum computer language
In a binary application hardware programming context forward, this can be useful.
But in a simple games, it has no use.
will use maybe in robotic programming with hardware.
ex:
http://xor.pw/

you can also use to make encode (Encrypt ) valur
http://md5decrypt.net/Xor/
 
Last edited:

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

Latest Threads

Latest Profile Posts

Julian Brooks wrote on Hudell's profile.
Hi, I'm trying to use the Orange Mapshot plugin on Mac, but it isn't working. Could you assist? I'm attempting to do Parallax Mapping. Thanks.
I can't believe my dlc flopped that hard. It's depressing. I'm a fricking failure at being a musician.
Person: "Taxes are bs and money is, too! Anarchy!!" *Literally anything goes wrong* Same Person: "Why hasn't the government fixed this???"
Stream will be live shortly with a session of Haunting Ground! Feel free to drop by!

Forum statistics

Threads
94,355
Messages
920,176
Members
124,111
Latest member
Azarae
Top