Neat little script

Posted by Bipshark on June 11, 2008, 6:41 a.m.

I've made a script for calculating speed with desired freq.

An example:

You create an object called objPlayer. On the left key event you use this code:

if(place_free(x-4, y)) { x-=4; }

And the user will move 4 pixels to the left.

However, if you set the roomspeed to the users screen hz. (ex. 60hz) the user will move 8 pixels to the left.

But if you use my script like this:

if(place_free(x-4, y)) { x-=freq_pixels(4); }

It will move 4 pixels to the left. And if the users screen hz was 100hz. It will still move 4 pixels to the left!

The script can be copied from below:

——–

var sp, freq, calc;

sp = argument0;

freq = display_get_frequency();

calc = (sp / freq) * 30;

return calc;

——–

Comments

PY 15 years, 10 months ago

Cool

raz 15 years, 10 months ago

may i change the code?

Instead of 30, use room_speed…

var sp, freq, calc;

sp = argument0;

freq = display_get_frequency();

calc = (sp / freq) * room_speed;

return calc;

Bipshark 15 years, 10 months ago

That won't work. Then it will return same value as input.

Try it yourself in gm.

raz 15 years, 10 months ago

This code makes the player to move 4 pixels as if the room speed was 30, ALLWAYS

noshenim 15 years, 10 months ago

Quote:
However, if you set the roomspeed to the users screen hz. (ex. 60hz) the user will move 8 pixels to the left.
in how many frames?

Quote:
It will move 4 pixels to the left. And if the users screen hz was 100hz. It will still move 4 pixels to the left!
in how many frames?

I don't get it >__<

sirxemic 15 years, 10 months ago

EDIT: it DOES work, but your description wasn't really clear.

Juju 15 years, 10 months ago

Well done, you've rediscovered delta time, only you've mutated it into some anal-raped abomination. Using the screen frequency only works if you're using synchronisation. Here, this is how it should be done:

return argument0 / fps * room_speed;

Also, you need to be using that function for the collision checking as well or else you may end up checking 4 pixels ahead and actually jumping forward 6, leading to embarassing sticking problems. Which I'm sure you and your sock are accustomed to.

Bipshark 15 years, 10 months ago

Sorry for my fail at the description. I'm not that good on english.