Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (TedMar), 1,420 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Call function from a function #411310
11/15/12 13:53
11/15/12 13:53
Joined: Feb 2006
Posts: 33
Herts, UK
D
danohu Offline OP
Newbie
danohu  Offline OP
Newbie
D

Joined: Feb 2006
Posts: 33
Herts, UK
Hi

In Workshop 3 the following code is provided which calls a function 'compute' from function main(). I want to be able to call a function from a function other than main e.g. replace function main () with something like function resp1 (). When I do this with the code below and call the 'compute' function it will not work. It would seem that you can only call another function from function main (). Would this be correct and if not how do I achieve this?

This is the original code from Workshop 3:

Code:
////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

var my_age = 33;
var days_a_year = 365;
var number_of_days; // we need to calculate this value

////////////////////////////////////////////////////////////////////

PANEL* pDisplay =
{
	digits (10, 10, 5, *, 1, number_of_days);
	flags = SHOW;
}

/////////////////////////////////////////////////////////////////////

 function compute_days()
 {
 	number_of_days = my_age * days_a_year;
}
function main()
{
	screen_color.blue = 150;
	compute_days();
}




If I change the code to what is below it does not work:



Code:
////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

var my_age = 33;
var days_a_year = 365;
var number_of_days; // we need to calculate this value

function resp1();

////////////////////////////////////////////////////////////////////

PANEL* pDisplay =
{
	digits (10, 10, 5, *, 1, number_of_days);
	flags = SHOW;
}

/////////////////////////////////////////////////////////////////////

 function compute_days()
 {
 	number_of_days = my_age * days_a_year;
}
function resp1()
{
	screen_color.blue = 150;
	compute_days();
}



Thanks for your help

Last edited by JustSid; 11/15/12 14:35. Reason: Added code tags
Re: Call function from a function [Re: danohu] #411318
11/15/12 14:11
11/15/12 14:11
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Well I'm not sure if I understood what you really want but:

The function 'main' is the only function that gets called automatically on startup - which means that renaming this function makes nothing happen on startup.

So it - of course - is possible to call functions from other functions than main.

and if you're posting code in future please use [code] at the beginning and [/code] at the end of your code. Much easier to read then wink

Last edited by Kartoffel; 11/15/12 14:32.

POTATO-MAN saves the day! - Random
Re: Call function from a function [Re: danohu] #411322
11/15/12 14:33
11/15/12 14:33
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: danohu
It would seem that you can only call another function from function main (). Would this be correct and if not how do I achieve this?

Almost correct. There is another possibility. You can also append "_startup" to a function name. In this case the function will be called automatically right after the main function. If you got multiple startup functions they get called in the order they are defined in as far as I remember.
Code:
function my_startup()
{
   printf("I started automatically");
}



Always learn from history, to be sure you make the same mistakes again...
Re: Call function from a function [Re: Uhrwerk] #411513
11/17/12 14:53
11/17/12 14:53
Joined: Nov 2011
Posts: 139
India
Yashas Offline
Member
Yashas  Offline
Member

Joined: Nov 2011
Posts: 139
India
Uhrwerk ,Thanks, I never knew that appending _startup to a function name starts automatically laugh

If I create multiple function as _startup.
1. Is the main executed first or the _startup??
2. How would I know which function having _startup wud be executed first??

Thanks once again laugh


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Call function from a function [Re: Yashas] #411519
11/17/12 14:59
11/17/12 14:59
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
1. Yes
2. AFAIK it's in the order they are defined in.

Example:
Code:
#include <acknex.h>

void b_startup()
{
	printf("B");
}

void main()
{
	printf("Main");
}

void a_startup()
{
	printf("A");
}


This sample should show message boxes in the order "Main", "B", "A"

For detailed documentation: http://www.conitec.net/beta/askript-befehl.htm


Always learn from history, to be sure you make the same mistakes again...
Re: Call function from a function [Re: Uhrwerk] #411520
11/17/12 15:01
11/17/12 15:01
Joined: Nov 2011
Posts: 139
India
Yashas Offline
Member
Yashas  Offline
Member

Joined: Nov 2011
Posts: 139
India
Thank You very much laugh


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Call function from a function [Re: Yashas] #411522
11/17/12 15:01
11/17/12 15:01
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Originally Posted By: Yashas
How would I know which function having _startup wud be executed first
Originally Posted By: Uhrwerk
If you got multiple startup functions they get called in the order they are defined in as far as I remember


regarding 1: test it

place error("something to identify the function"); in the first line of a _startup-function and in the first line of main()

The error which appears first belongs to the function that gets called first:


EDIT: and again... Uhrwerk was faster grin

Last edited by Kartoffel; 11/17/12 15:01.

POTATO-MAN saves the day! - Random
Re: Call function from a function [Re: Kartoffel] #411523
11/17/12 15:05
11/17/12 15:05
Joined: Nov 2011
Posts: 139
India
Yashas Offline
Member
Yashas  Offline
Member

Joined: Nov 2011
Posts: 139
India
^ grin Thank You both


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Call function from a function [Re: Yashas] #411528
11/17/12 15:12
11/17/12 15:12
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
If you're lazy you don't even need printf. All automatically started functions are logged in acklog.txt.


Always learn from history, to be sure you make the same mistakes again...

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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