How can I convert this Ruby Code to JS?

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Hey guys I had a Linear code where Galenmereth helped me to create for doing lineart movement more "easily" in Ace...

Now though I want to convert it to MV but I don't know how to properly convert it to JS

here the code

#---------------------------------------------------------------------------- # ○ new method: lineart #---------------------------------------------------------------------------- # * t = Current time (frame) # * b = Start value # * c = Target value # * d = Duration total (frames) # * Returns: Value modified by t def lineart(t, b, c, d) return c*t/d.to_f + b end thanks for any further answer :)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
It's pretty much exactly the same.

Code:
Class_Name.prototype.lineart = function(t, b, c, d) {  return c * t / d + b;}
You don't need to_f because JS uses floats by default, and both the old and the new would return a float. The only thing you left out was what class this method belongs to.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
It's pretty much exactly the same.

Class_Name.prototype.lineart = function(t, b, c, d) { return c * t / d + b;}You don't need to_f because JS uses floats by default, and both the old and the new would return a float. The only thing you left out was what class this method belongs to.
thanks shaz yeah well this method will be had directly to my Extended sprite class thanks for your answer :)
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
in regards to more complicated ruby code I wouldn't.  I would just re-write it from scratch There are tools out there to do this how ever the code they produce is often un readable and unmaintainable.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
in regards to more complicated ruby code I wouldn't.  I would just re-write it from scratch There are tools out there to do this how ever the code they produce is often un readable and unmaintainable.
I approve although this little line's of code do the same's job both in Ruby in JS so no need to rewrite everything's lol

the only big difference would be is I don't need to convert to float
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
In this case, it's one of Robert Penner's easing functions, which have been translated in a whole bunch of languages, so you could just google for them ^^
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top