Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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 (AndrewAMD), 1,534 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Questions about: How to create a macro function? #431706
10/22/13 18:38
10/22/13 18:38
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Hello friends.

with the purpose of maintaining the proper functioning of my functions that are linked to a DLL, i need use the function "wait_for" always after performing some function of the dll.
Sample:

Code:
int select = sql_select("SELECT * FROM terrains");
	wait_for(sql_select);

        if(select)
        ...


This Became too boring, because I need to do this many, many times throughout the script. (wait_for()...wait_for() ...)

Is there any way to create a macro linked to functions?
Whenever I call a function, it automatically performs another function in end?


Last edited by NeoNeper; 10/22/13 18:39.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: Questions about: How to create a macro function? [Re: NeoNeper] #431707
10/22/13 19:36
10/22/13 19:36
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Code:
function sql_select(STRING *strCommand, void *pFunction)
{
	int iSelection = sql_select(strCommand);
	wait_for(sql_select);
	
	if(iSelection)
	{
		void tFuncTypedef();
		tFuncTypedef = pFunction;
		tFuncTypedef();
	}
}



Change the typedef if you need params laugh

Last edited by Ch40zzC0d3r; 10/22/13 19:37.
Re: Questions about: How to create a macro function? [Re: Ch40zzC0d3r] #431712
10/22/13 20:22
10/22/13 20:22
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Chaos, I'm pretty sure Neo wanted to automate the wait_for(), not have a callback function...

Which, by the way, doesn't work. Nor does it need to, because wait_for() will always return immediately, since Neos DLL method will never ever be registered as still running in the engines Scheduler (no will it ever appear there as anything). No idea why he thought wait_for() is needed there, but it's definitely not.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Questions about: How to create a macro function? [Re: WretchedSid] #431714
10/22/13 20:29
10/22/13 20:29
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Hm probably I understood it wrong.
However, he should code his own wait_for function, like a while which waits until iSelection is bigger then -1 or something.

Re: Questions about: How to create a macro function? [Re: Ch40zzC0d3r] #431716
10/22/13 20:51
10/22/13 20:51
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
But why?! iSelection (by the way, you are doing hungarian notation wrong) doesn't change after sql_select was called. Ever.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Questions about: How to create a macro function? [Re: WretchedSid] #431718
10/22/13 21:19
10/22/13 21:19
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Well then I completely missunderstood what he wants to achieve sry.

Re: Questions about: How to create a macro function? [Re: Ch40zzC0d3r] #431720
10/22/13 21:45
10/22/13 21:45
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
The code from the original poster is already flawed. That's the problem. He has misunderstood the conception of wait and return.


Always learn from history, to be sure you make the same mistakes again...
Re: Questions about: How to create a macro function? [Re: WretchedSid] #431742
10/23/13 11:11
10/23/13 11:11
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Originally Posted By: JustSid
Chaos, I'm pretty sure Neo wanted to automate the wait_for(), not have a callback function...

Exactly (^.^).

Originally Posted By: JustSid

Which, by the way, doesn't work. Nor does it need to, because wait_for() will always return immediately, since Neos DLL method will never ever be registered as still running in the engines Scheduler (no will it ever appear there as anything). No idea why he thought wait_for() is needed there, but it's definitely not.


I really did not know that. Thanks for clarifying.
however, the lack of it generates crash in my functions, since sometimes the function attempts to validate variables that have not time to get a true value.

below show an excerpt from my script that fails to validate a true value if I do not use a standby.

Code:
int results = sql_get_rows(); //DLL FUNCTION
wait_for(sql_get_rows);	//the "wait" that I thought that would work	
if(results) 
{
...
}




If I remove the wait_for of the script, the "if(results)" may not receive a true value, because the function of the DLL may not havê had time to return a valid result.

believe then that the most efficient way would be to use a simple "wait(1);". This is correct?


Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: Questions about: How to create a macro function? [Re: NeoNeper] #431745
10/23/13 11:27
10/23/13 11:27
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
You should read my post again, I said something like that before.
Just change the dll function or do it like this:
Code:
int iResults = -1;
iResults = sql_get_rows();
while(iResults == -1) wait(1);
if(iResults)
{
     ...
}



true == 1
false == 0

-1 should stay as long as the function didnt return ANYTHING.

Last edited by Ch40zzC0d3r; 10/23/13 11:56.
Re: Questions about: How to create a macro function? [Re: Ch40zzC0d3r] #431756
10/23/13 13:29
10/23/13 13:29
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You both misunderstand the concept of "return". You cannot mix wait and return.

The first possibility is that sql_get_rows immediately returns a value. In this case iResults has a meaningful value and waiting may either happen forever (because sql_get_rows returned -1) or may not happen at all (because sql_get_rows returned something different).

The second possibility is that sql_get_rows does not return anything. In this case iResults is either random or remains at -1. I don't know. try it if you're interested.

Regardless of the possibilities described above iResults will never change afterwards so that the while loop is pointless.


Always learn from history, to be sure you make the same mistakes again...
Page 1 of 2 1 2

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