My questions...

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

Previous topic - Next topic

FanOfHumor

It seems that I am going to be asking many simple questions that don't deserve a topic.So I thought I could just ask them here whenever I need to.


So the first question is:
Is there a way to create an animation and then delete it once its finished.I tried using overlays and dynamicsprites but those don't work as well as objects. I heard somewhere that you can't delete objects.So is there another way?
Second question:
Does the mere existence of an object in a room effect game speed at all? Even if its not visible?

Crimson Wizard

#1
Quote from: Pajama Sam on Sat 23/04/2022 15:47:39
Is there a way to create an animation and then delete it once its finished.I tried using overlays and dynamicsprites but those don't work as well as objects. I heard somewhere that you can't delete objects.So is there another way?

Using room objects or characters: make them hidden by default, make visible when necessary, play animation and hide again.
If this is the effect that happens alot in different rooms - then character is a better choice. Objects have Visible flag, Characters don't for some weird reason, but you can set character to a non-existing room when it's no longer needed (e.g. Char1.ChangeRoom(-1)).


Quote from: Pajama Sam on Sat 23/04/2022 15:47:39
Does the mere existence of an object in a room effect game speed at all? Even if its not visible?

No.

FanOfHumor


FanOfHumor

When making functions how would a parameter be made as optional?

Crimson Wizard

Quote from: Pajama Sam on Sun 24/04/2022 04:20:17
When making functions how would a parameter be made as optional?

You tell it a default value in the function declaration:
Code: ags

function func(int a = 10);

FanOfHumor

This keeps giving me an error(Invalid use of '*').What's the problem?

String* text=text.Append("eOnce");

Khris

You don't need an asterisk when declaring a String.
Also you are using the  text  variable, which you are declaring here, as if it already existed. What are you trying to achieve? And why would you append "eOnce" to a string?

FanOfHumor

I have a function that inputs chosen settings into GLOB.Animate.I want the strings text either eRepeat or eOnce to be placed into GLOB.Animate where its needed.How would eOnce and eRepeat be made available as a parameter for a function. I assume there is a better way than using string.

Snarky

#8
Quote from: Pajama Sam on Tue 26/04/2022 07:02:09
I want the strings text either eRepeat or eOnce to be placed into GLOB.Animate where its needed

I don't think that's what you want. I think you want the values eOnce or eRepeat to be passed to the .Animate() method.

eOnce and eRepeat are values of the enum RepeatStyle, so you can just declare a parameter of the RepeatStyle type, just like the .Animate() method does.

The difference between the String "eOnce" and the value eOnce is a fundamental coding concept that is important to learn and understand. It's just like the difference between the String "true" and the boolean value true. The String "true" is just a sequence of four characters: [t,r,u,e]. AGS just stores it, it doesn't understand what it means. You can't write something like if(gWindow.Visible == "true"), because now you're comparing a boolean .Visible with a String "true," and that's like asking "which is bigger, the number 5 or a post-it note?" It doesn't make sense. It doesn't matter what's written on the post-it note: it might be "Hello" or "4"; it's still not comparable. (There are ways to read the text of the String/post-it note and convert it to a boolean or number, but then you would have to code that.)

The value true on the other hand is recognized when you compile the code, and converted into the computer's internal representation of the concept of truth (which is actually just a number, usually either 1 or -1). This allows it to be used in logical expressions, for example if(gWindow.Visible == true). When it is compiled, the actual words you've typed in the code are discarded, so that the internal representation of if(gWindow.Visible == true) doesn't contain the string "true".

Khris

Exactly, here's example code:

Code: ags
// top of global script
RepeatStyle GLOB_Repeat; // type RepeatStyle (int would also work) enables the correct auto-complete options

// inside some function
  GLOB_Repeat = eOnce; // no quotes, no strings are involved at any point

// elsewhere:
  player.Animate(..., GLOB_Repeat);

FanOfHumor

Thanks khris and snarky.

FanOfHumor

#11
How would I place the parameter globrepeatstyle in this function?

function nbobj(Object* GLOBALOBJ, int xpos, int ypos, int objview,int loop,int frame, int delay,globrepeatstyle)

EDIT:
Nevermind. I figured it out.

FanOfHumor

#12
I have this script here that seems to totally ignore the else statement.I'm trying to get the character to only be visible while speaking.So what's the problem with this?
Code: ags

  if(cfattymouth.Speaking)
  {
    cfattymouth.Transparency=0;
  }  
  else
  {
    cfattymouth.Transparency=100;
  }  

By the way.This is in repeatedly execute.

Crimson Wizard

Quote from: Pajama Sam on Tue 10/05/2022 14:14:06
I have this script here that seems to totally ignore the else statement.I'm trying to get the character to only be visible while speaking.So what's the problem with this?
Code: ags

  if(cfattymouth.Speaking)
  {
    cfattymouth.Transparency=0;
  }  
  else
  {
    cfattymouth.Transparency=100;
  }  

By the way.This is in repeatedly execute.

"repeatedly_execute" is not called during blocking actions, including blocking speech. Try placing this in "repeatedly_execute_always" instead.

More info on this: https://adventuregamestudio.github.io/ags-manual/RepExec.html

FanOfHumor

Thanks.I'll do that.Now for the sake of clarity.Since a room's script does not have repeatedly execute always it would not be able to do this script.Right?

Khris

You can do it in room scripts;  repeatedly_execute_always  is one of a few functions you can just add and they get called automatically, without the usual event linkage (the others being on_key_press and on_mouse_click).

FanOfHumor

#16
Is there a plausible way to do costumes in AGS that are like extra layers/limbs?

Crimson Wizard

#17
Quote from: Pajama Sam on Wed 11/05/2022 17:10:40
Is there a plausible way to do costumes in AGS that are like extra layers/limbs?

Similar questions have been asked couple of times only recently, here are related discussions:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=59912.0
https://www.adventuregamestudio.co.uk/forums/index.php?topic=59954.0

PS. I feel like we would benefit from a good tutorial and maybe an article in the manual on this topic.

FanOfHumor

Does drawing dynamic sprites have a baseline or z-order?

Crimson Wizard

Quote from: Pajama Sam on Wed 11/05/2022 18:50:37
Does drawing dynamic sprites have a baseline or z-order?

Dynamic sprites are just raw graphic, they dont have any baseline or position on their own. But they may be drawn on or assigned to an object, and object has a baseline or z-order.

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