PDA

View Full Version : maki "psuedo-slider" help


rintaro82
8th October 2002, 11:31
hi all. can someone out there tell me why this script doesn't work? it's supposed to cause a layer ("push") to slide across a 70 pixel area in time to the song which is playing.

#include "../../../lib/std.mi"

global layer mybutton;
global group mybuttongroup;
global timer mytimer;

system.onscriptloaded()
{
mybuttongroup = getscriptgroup();
mybutton = mybuttongroup.findobject("Push");
mytimer = new timer;
mytimer.setdelay(1000);
}

system.onplay()
{
mytimer.start();
}

mytimer.ontimer()
{
if (system.getplayitemlength() > 0)
{
float played = system.getposition();
played = played / system.getplayitemlength();
int setX = 70 * played;
mybutton.resize(setX,20,20,20);
mybutton.fx_update();
}
}


i realize there is nothing in there to bring the layer back to the beginning, but i'm just trying to get the guts work at this point. i also realize that i really don't know what i'm doing here, so it might be something stupid.

in case it's important, "push" is defined in my player.xml simply as a 20 X 20 layer at x="100" and y="20".

thanks in advance!

will
8th October 2002, 13:03
the best way to set the co-ords of a layer is to use guiobject.setxmlparam("x",integertostring(setX));
or whatever

Hollow
8th October 2002, 15:15
First off, you don't need the Fx_Update() line. Resize is not a layer fx function. So you can remove that.

I suspect that it doesn't work because you are doing floating point division and storing the value to an int. try doing something like this.

double setX = 70 * played;
MyButton.resize(Integer(setX),20,20,20);

or

int setX = Integer(70 * played);
MyButton.resize(setX,20,20,20);


the point of all this being, that i don't think maki will convert the type for you. Consider it like typecasting in c++. int setx = (int)(70*played), its just that maki uses a function call (system.integer(double d)) to do the same thing.

But like will fisher said, SetXmlParam might be a better choice, It really depends on you and how you want to do this and what you want to do with it latter. To me they both have good and bad points.

rintaro82
9th October 2002, 10:18
thanks to both of you for the input. i'll have to try both methods to see which one works best.