Sign in to follow this  
Followers 0
Pixel

Returning to the start of a function or w.e

8 posts in this topic

Say if I had a code like this for example

 

function()
{


if( self UseButtonpressed() )
{


self thread anotherfunction();


}
else if( self MeleeButtonPressed() )
{


//Go back to the start of this whole thing ( function() ) - like a loop I guess


}


}

How would I do that? I have a faint idea, but not certain.

0

Share this post


Link to post
Share on other sites

Firstly what is up with your formatting? Dear god.

 

Secondly, maybe something along the lines of this:

function()
{
	for(;;)
	{
		if( self UseButtonpressed() )
		{
			self thread anotherfunction();
			break;		
		}

		else if( self MeleeButtonPressed() )
			continue;
	}
}
1

Share this post


Link to post
Share on other sites

add

 

wait 0.05;

 

before the end of the loop or the thread will be terminated if you press and hold melee button due to infinite loop without waits :dave:

2

Share this post


Link to post
Share on other sites

add

wait 0.05;

before the end of the loop or the thread will be terminated if you press and hold melee button due to infinite loop without waits :dave:

Well spotted, thanks.
0

Share this post


Link to post
Share on other sites

Another quick question, say I had two functions.

 

The first function has been completed, it has threaded another function, and scripts are running in the second function now.

 

How'd I make it so the second function can go back to the first function?

 

so like:

function()
{
	for(;;)
	{
		if( self UseButtonpressed() )
		{
			self thread anotherfunction();
			break;		
		}

		else if( self MeleeButtonPressed() )
			continue;
	}
}

anotherfunction()
{
	for(;;)
	{
		if( self UseButtonpressed() )
		{
			self iPrintLnBold( "Example" );
			//this line would go back to function() - Is this possible? Never done it before, and it would make things so much easier for me D:	
		}

		else if( self MeleeButtonPressed() )
			continue;
	}
}

Edit: nvm, a friend helped me over steam, thanks for the help bear and sentrex!

0

Share this post


Link to post
Share on other sites

GSC:

function()
{
	[[...do something...]]


	if( goback )
	{
		thread function();
		return;
	}

	[[...do something...]]
}

or C:

void function()
{
beginning:
	[[...do something...]]


	if( goback )
	{
		goto beginning;
	}

	[[...do something...]]
}

Either way, i strongly encourage not to do this

 

 

goto.png

1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0