My questions...

Started by FanOfHumor, Sat 23/04/2022 15:47:39

Previous topic - Next topic

FanOfHumor

Is there a way to easily delay reading script without blocking?

Crimson Wizard

Quote from: Pajama Sam on Wed 11/05/2022 19:03:58
Is there a way to easily delay reading script without blocking?

Please elaborate?

FanOfHumor

Is there another way than Wait(); that doesn't block.So far what I use is a integer adding up and whenever the integer reaches a number it runs certain script.This way works but you have to place the script in an if statement.I'm looking for something that merely stops reading of the script for a set time without blocking the already running scripts such as animations and mouse cursor.

Crimson Wizard

#23
Quote from: Pajama Sam on Wed 11/05/2022 19:40:05
Is there another way than Wait(); that doesn't block.So far what I use is a integer adding up and whenever the integer reaches a number it runs certain script.This way works but you have to place the script in an if statement.I'm looking for something that merely stops reading of the script for a set time without blocking the already running scripts such as animations and mouse cursor.

I am still not sure what the problem is, as Wait does that: it stops execution of the current script and does not block the active animations and the mouse cursor. Perhaps if you tell why you cannot use Wait, or expain your situation in more detail?

In general, if you need to wait until something, then it's one of the two solutions:
1. If you want to stop script right in the middle of the current function, then use Wait, and optionally some conditions to see at which point it needs to stop waiting.
2. Use timers, or any alternatives (like integer counters), and check in repeatedly_execute and similar functions to see when they are over.

The case 2 is also when you need player to keep ability to interact with things.

Khris

Quote from: Pajama Sam on Wed 11/05/2022 19:40:05This way works but you have to place the script in an if statement.
This is the only way to delay code non-blocking. If you want cleaner code, you can move the commands to a new custom function and call it:

Code: ags
function stuffHappens() {
  // code here
}

// in rep_ex_always
  if (my_timer >= 4000) stuffHappens();

FanOfHumor

I have a question that i'm sure was answered but I can't find it so i'll ask it again.How can I add a number to the name of something.Such as having an overlay that is made every time a function is called and the name of the new overlay is called myoverlay(number).To add a number to the overlays name every time its made so that it can be recalled through script without changing the previous one.I'm not asking how to change it every time its made.I'm asking how to add a number to the end of its name.

Snarky

#26
As explained last time around, you can't, but this is a typical use-case for an array.

Also check out the last bit of this post (from "this is a common misunderstanding") for an explanation of why what you describe cannot be done.

FanOfHumor

#27
I keep getting an error "something has a parse error".Something needs to be accessible by all of this script but I don't know how to put the parameter in the function and have it global.
Code: ags

int timer;
int startanimation;
int playagain;
function overplay(int xpos, int ypos,int something, int other,RepeatStyle)
{
	flap=Overlay.CreateGraphical(xpos, ypos, sprite);
	startanimation=1;
	flap.Graphic=something;
}	
function overplayagain(int something2, int other2,RepeatStyle)
{
	startanimation=1;
	playagain=1;
}	
function Repeatedly_execute_always()
{
	if(startanimation==1)
	{
		timer =1;
	}	
	if(timer>=40)
	{
		timer=0;
		startanimation=0;
		if(playagain==1)
		{
			flap.Graphic=something2;
		}
		if(playagain==0)
		{
			flap.Graphic=something;
		}	
	}	
	if(backwards==true)
	{
		
		if(something>other)
		{
			something-=1;
		}
	}	
	if(backwards==false)
	{
		if(something<other)
		{
			something =1;
		}
	}	
		if(backwards==true)
	{
		
		if(something2>other2)
		{
			something2-=1;
		}
	}	
	if(backwards==false)
	{
		if(something2<other2)
		{
			something2 =1;
		}
	}	
	
}	

Code: ags

import function overplay(int xpos, int ypos,something, int other,direction param);

import function overplayagain(something2, int other2,direction param);


Khris

The function in your script is supposed to something like
Code: ags
function overplay(int xpos, int ypos, int something, int other, RepeatStyle rs) {


RepeatStyle is just the type, you also need a name in order to be able to reference the passed value inside the function: if (rs == eOnce) ...
To make the function globally available, basically copy the line:

Code: ags
// in the header
import function overplay(int xpos, int ypos, int something, int other, RepeatStyle rs);

FanOfHumor

#29
Thanks!

I have another problem now.This script is meant to animate an overlay but it's not  changing  to the next sprites.What is the reason for its not changing to the next sprite?

Certain integers and an overlay are declared global in "global variables".
globover2=overlay
backwardsnum=integer
somethingnum=integer
othernum=integer
backwardsnum2=integer
somethingnum2=integer
othernum2=integer
Code: ags

int timer;
int startanimation;
int playagain;
function overplay(Overlay* globover, int xpos, int ypos, int something, int other, bool backwards)
{
  globover=Overlay.CreateGraphical(xpos, ypos, 26);
  startanimation=1;
  globover2=globover;
  backwardsnum=backwards;
  somethingnum=something;
  othernum=other;
  playagain=0;
}       
function overplayagain(int something2, int other2,bool backwards2)
{
  backwardsnum2=backwards2;
  somethingnum2=something2;
  othernum2=other2;
  startanimation=1;
  playagain=1;
}       
function Repeatedly_execute_always()
{
  if(startanimation==1)
  {
    timer+=1;
  }       
  if(timer>40)
  {
    if(playagain==1)
    {
      if(backwardsnum2==true)
      {
          
        if(somethingnum2>othernum2)
        {
          somethingnum2-=1;
        }
      }       
      if(backwardsnum2==false)
      {
        if(somethingnum2<othernum2)
        {
          somethingnum2+=1;
        }
      }
      globover2.Graphic=somethingnum2;
    }
    if(playagain==0)
    {
      if(backwardsnum==true)
      {
        if(somethingnum>othernum)
        {
          somethingnum-=1;
        }
      }       
      if(backwardsnum==false)
      {
        if(somethingnum<othernum)
        {
          somethingnum+=1;
        }
      }     
      globover2.Graphic=somethingnum;
    }
    timer=0;
  }              
        
}    

EDIT:
Finally after days of strenuous searching I finally found the reason for this not animating.Reapeatedly execute was not actually repeately execute.It was making it a custom function.Now that that's fixed it animates flawlessly.
DOUBLE EDIT:

How do I change this script to animate an unknown number of multiple overlays?

SMF spam blocked by CleanTalk