Problems Scripting Commands with Scrolling Background

Started by Jaffles, Wed 21/03/2012 03:05:18

Previous topic - Next topic

Jaffles

Hey guys, as you may recall, a few of you graciously helped me put together a scrolling background a few weeks back.
Upon returning to that section of my project, and trying to script some racing action on top of the background, I've run into a few problems. This is the script I'm using.

function room_RepExec()// this scrolls the background
{


  if (oRoad.Visible==true && oFinish.X >= 400) {
    oStart.X -=20;
    oRoad.X -= 20;  // speed
    if (oRoad.X <= -640) oRoad.X += 640;
  }
  if (oDracoRacer.X >= 350) {
    oFinish.Move(400, 349, 20, eNoBlock, eAnywhere);
}

function room_AfterFadeIn()// this controls the racer's (oDracoRacer) movement
{
oDracoRacer.SetView(20);
oDracoRacer.Animate(0, 5, eRepeat, eNoBlock, eForwards);
oDracoRacer.Move(200, 312, 5, eNoBlock, eAnywhere);
oDracoRacer.Move(100, 312, 4, eNoBlock, eAnywhere);
Wait(200);
oDracoRacer.Move(700, 312, 5, eNoBlock, eAnywhere);
}

There are a few problems I'm encountering. If I set the move commands to eBlock then they stop the background from scrolling, but if I set them to eNoBlock then they muddle together instead of being three separate movements. Also, the wait command stops the background from scrolling as well. Finally when oDracoRacer's x coordinate exceeds 350, the finish line does not move onto the screen.

TLDR: Is there any way I can have the RepExec script running, while stopping the RoomLoad one?

Also, how do you guys post your code in those neat little white boxes? I'd like to start doing that, just for everyone's sake XD
   

Khris

When you're composing your post, there's a link right above the row of smilies that says "How do I post images, smileys and formatting?".
To get a code box, use [code]code here[/code]

Re your problem:
move the RepExec code into a new function and call it repeatedly_execute_always.

The reason why oFinish isn't moved is because you're restarting the movement every game loop, so oFinish doesn't have a chance to move at all. If this is a one-time event, this will work:

Code: ags
  if (oDracoRacer.X >= 350 && Game.DoOnceOnly("move finish line")) {
    oFinish.Move(400, 349, 20, eNoBlock, eAnywhere);
  }

Jaffles

Thanks for the Help Khris! The repeatedly_execut_always works perfectly. Unfortunately, I do need the finish line to scroll more than once (you can try the race repeatedly, and lose if you haven't done certain things to your vehicle). I don't have the room saving state, but the game still only runs the finish line once.
   

Khris

In that case you have to use a variable. We'll only need it in that particular room, so simply declare it at the very top of the room script:

Code: ags
bool finish_line_moved;  // no initial value stated -> false


At the start of race / when the room is entered, reset it to false:
Code: ags
  finish_line_moved = false;


Then change the oFinish part to this:

Code: ags
  if (oDracoRacer.X >= 350 && !finish_line_moved) {
    oFinish.Move(400, 349, 20, eNoBlock, eAnywhere);
    finish_line_moved = true;
  }


As before, the .Move command is called only once, but unlike with Game.DoOnceOnly, we can reset the flag each time the race starts.

SMF spam blocked by CleanTalk