Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, RealSerious3D, BrainSailor), 1,265 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Switching Functions #298103
11/11/09 22:49
11/11/09 22:49
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
Is it possible to switch back and forth between functions?
The first function starts the second, then the second starts the first.

Code:
function test1()
{
	blah blah;
	function test0(); //this wouldn't work
}

function test0()
{
	blah blah;
	function test1();
}




I thought of a way to do it but I am not sure how this affects memory, because my

models react different now. Here is what I tried:

Code:
while(1)
{
	//timer to switch direction functions
	if (myTimer == 0)
	{
		randomize();
		wait(random(20));
		myTimer = 1;
	}
	else
	{
		randomize();
		wait(random(20));
		myTimer = 0;
	}
	wait(1);
}


if (myTimer == 0)
{function test0();}
else {function test1();}



Is this method ok, or does it use too much memory? If it does, is there a better way?

Or back to my first question - Is it possible to switch back and forth between

functions?

Re: Switching Functions [Re: JGGamer] #298173
11/12/09 18:13
11/12/09 18:13
Joined: Aug 2003
Posts: 7,439
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,439
Red Dwarf
Code:
function test1()
{
	blah blah;
	test0();
}

function test0()
{
	blah blah;
	test1();
}




"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: Switching Functions [Re: Michael_Schwarz] #298194
11/12/09 19:49
11/12/09 19:49
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Code:
function test0(); // Don't forget this line ;)

function test1()
{
	blah blah;
	test0();
}

function test0()
{
	blah blah;
	test1();
}



Re: Switching Functions [Re: Lukas] #298233
11/13/09 01:34
11/13/09 01:34
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
Sorry I misled you with my code. I didn't have function in front of test. I made a mistake while copying and pasting. My codes read like yours.
Only take note of the bold text:

function test1()
{
blah blah;
function test0(); //this wouldn't work
}

function test0()
{
blah blah;
function test1();
}

It wouldn't work because the funtion must be read first before it is called, if not an error occurs.

This I got from the lite-c worksops:
Quote:
Important tip: write the lines of code for your functions first and call them later. The engine reads the code the same way you read a book: it starts with the top of the script page and goes down to the bottom, reading the code line by line. If I would write my script this way

function main()
{
compute_days();
}

function compute_days()
{
number_of_days = my_age * days_a_year;
}

the engine will say: oh, that's function main. I know function main; I need to run it every time. What does it say now? compute_days(). What's with this function? I don't know it! I don't know what it wants from me. I'm going to display an error message and I will take the rest of the day off:


That's why I want to know if there is any possible way to switch between two functions.


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1