(Solved)Have integer=something only once in repeatedly execute.

Started by FanOfHumor, Fri 04/02/2022 01:44:33

Previous topic - Next topic

FanOfHumor

I have an integer that should = player.y whenever the if statement is true.I don't know how get this to continuously check the if statement without changing the integer continuously.
Code: ags

function repeatedly_execute_always()
{
    if(stopidledirect>player.y+6)
    {
        stopidledirect=player.y;
        max.y+=5;
    }	
    if(stopidledirect<player.y-6)
    {
       stopidledirect=player.y;
       max.y-=5;
    }	
}


eri0o

Hey Pajama Sam,

What are you trying to achieve? And what is wrong?

FanOfHumor

I need the integer stopidledirect to = player.y  whenever stopidledirect>player.y+6.I can't do this in repeatedly execute because then stopidledirect always =player.y.I need it to store the position of the player to compare how far he's moved.So in simple I need the player to move 6 pixels down then stop then move 6 pixels up and repeat this in a loop.This is meant for any player position.I would have done idle views but my character looks different every room.I don't want to have any more views just to move up and down.

Snarky

OK, so your first and second explanation are not at all equivalent, and your logic is very confused (the problem has nothing to do with repeatedly_execute), but I think I see what you're getting at.

What you want/need here is to keep track of the displacement from the "actual" y position, as well as the current direction of motion. Something like:

Code: ags

int playerDisplace;
int playerMove = 1;

function repeatedly_execute_always()
{
  if(playerDisplace>6 || playerDisplace<-6)
    playerMove = -playerMove;

  player.y += playerMove;
  playerDisplace += playerMove;
}


This should make the y-position bounce up and down within 6 pixels of the initial player.y.

However, setting player.y directly in this way has a number of potentially negative side effects. It can put the character outside any walkable areas, for exampleâ€"but that doesn't actually matter, since any time you set the x/y coordinate directly, you interrupt any walk the character may be doing. So by doing this every loop, you make it impossible for the character to walk anywhere. They will be stuck bouncing up and down in the same position.

Fortunately, AGS has something very much like "playerDisplace" built in, namely the Character.z coordinate. This allows you to shift the apparent position of the character up/down without affecting their actual position. I believe you can do this even while a character is walking. So try this:

Code: ags

int playerMove = 1;

function repeatedly_execute_always()
{
  if(player.z>6 || player.z<-6)
    playerMove = -playerMove;

  player.z += playerMove;
}

SMF spam blocked by CleanTalk