weird object moving! horror!

Started by Goldmund, Thu 15/01/2004 18:06:06

Previous topic - Next topic

Goldmund

I did a simple script for an object to move back and forth. Not much, 5 pixels. You know,

(enter screen)
MoveObjectDirect(1,122,100,5);

repeatedly execute:
if (GetObjectX(1)==122) MoveObjectDirect(1,117,100,5);

if (GetObjectX(1)==117) MoveObjectDirect(1,122,100,5);

Now, there are plenty of moving objects in my game, I know how to do it, and they move mighty fine.
Not this one in Room65. It just stands in place, until any left-click is processed, and THEN it jumps straight to the second position. No movement, just jumping when left-button in clicked.
Anyone experienced this??
p.s.version is 2.56

Scorpiorus

#1
Well, the movement speed measured in room pixels per game loop. So, if you move an object for 5 pixels with 5 pixels/loop speed (as you do) it just jumps to its destination. Try decreasing objects' speed down to 1-2.

~Cheers

Goldmund

Hmm that's an interesting idea, and I will try it when I'm back at the Donnacomputer, but if you were right, how come the object only jumps between two positions when a left-click is executed?

Gilbert

Well:
if (GetObjectX(1)==122) MoveObjectDirect(1,117,100,5);
else if (GetObjectX(1)==117) MoveObjectDirect(1,122,100,5);

Because like Scorpiorus said, since the speed may be too fast, it's possible that the object would be stuck in place at x-coordinate 122 with your code (actually I'm quite curious at why the object would ever move with clicking), but of course if the speed is lowered the "else" is not longer necessary.

Scorpiorus

I think actual moving starts after the script is finished, so that is why it moves even without else if. Though, I ain't sure about left clicking as well... :P

Goldmund

Failure and despair! I rage.
Your suggestions didn't help, the object still moves to another position only when mouse button is clicked. It's so strange that I think I'm going mad.
Maybe you'll take a look at my room script?
(Ps. object 1 is a separate one, just an animating light that works very fine)

// room script file
int poswind=0;

function room_a() {
 // script for room: Player enters screen (before fadein)
SetObjectFrame(1,12,13,0);  
}

function room_b() {
 // script for room: Player enters screen (after fadein)
AnimateObject(1,13,15,1);  
MoveObjectDirect(0,122,110,3);
}

function room_c() {
 // script for room: First time player enters screen
MoveCharacter(EGO,81, 149);
show_gui();  
AnimateObject(1,13,15,1);  
MoveObjectDirect(0,122,110,3);
}

function room_d() {
 // script for room: Repeatedly execute

if (GetObjectX(0)==122) {
 poswind=1;
 SetTimer(2,20);

 }


if ((IsTimerExpired(2)==1)&&(poswind==1)) {
 poswind=0;
 MoveObjectDirect(0,117,110,3);
 }

if (GetObjectX(0)==117) {
 MoveObjectDirect(0,122,110,3);
 }

}

Pumaman

if ((GetObjectX(0)==122) && (poswind == 0)) {
poswind=1;
SetTimer(2,20);

}


at the moment, timer 2 is continually reset so it never gets a chance to expire.

Goldmund

#7
Ha ha! Solved!
Influenced by Chris' advice, I also had to introduce poswind=2 because when the object was at 117 it continously "started" moving - and I didn't know that the command to start moving repeated endlessly held the object in one place.
Now, the left click issue: it just seems that when when the left button was clicked on something, the global script started running and blocked the object from being held in place by commands from the repeated script.

Thanks all! I'm happy now.

SMF spam blocked by CleanTalk