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
2 registered members (AndrewAMD, Nymphodora), 1,592 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Questions about: How to create a macro function? [Re: Uhrwerk] #431758
10/23/13 13:36
10/23/13 13: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
I dont get you.
Im doing this on all of my functions and it works just perfectly fine.
A function HAS to return something if its NOT a void, my code always returns > 0 means the variable is -1 if the function is not finished yet.

Last edited by Ch40zzC0d3r; 10/23/13 13:37.
Re: Questions about: How to create a macro function? [Re: Ch40zzC0d3r] #431759
10/23/13 13:49
10/23/13 13:49
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: Ch40zzC0d3r
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.


on the exact moment in that i set iResults = sql_get_rows(); , iResults
ceases to be "-1". Same the function have not had the time to return some value.

I am not 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] #431762
10/23/13 14:11
10/23/13 14:11
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
@Chaoscoder: The problem is that a wait won't let the calling function wait. The calling function will continue to run regardless of the scheduler state of any called function. That means you should not use wait and afterwards a return. When you use a return statement it must be executed in the exactly same frame as the function was called. Hence you cannot wait for return values. Either the value was returned immediately or no value at all will be returned. Example:
Code:
int foo()
{
  wait(1);
  return 1337; // Don't do this! It's wrong!
}
void bar()
{
  int i = 0;
  i = foo(); // Don't do this!
  while (!i) wait(1); // Pointless. The assignment to i has already been done. i won't change eventually.
}



Always learn from history, to be sure you make the same mistakes again...
Re: Questions about: How to create a macro function? [Re: Uhrwerk] #431765
10/23/13 14:30
10/23/13 14:30
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 if you do network stuff you HAVE to wait because your internet is not as fast as your CPU. I wont wait for a return value too, thats why I said change the code in the dll, but if he cant thats a way I would use.

Re: Questions about: How to create a macro function? [Re: Ch40zzC0d3r] #431767
10/23/13 14:38
10/23/13 14: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á
Originally Posted By: Ch40zzC0d3r
Well if you do network stuff you HAVE to wait because your internet is not as fast as your CPU. I wont wait for a return value too, thats why I said change the code in the dll, but if he cant thats a way I would use.


Exactly that. This is why I need to synchronize the receipt of the functions of the DLL with the functions used in the engine!

Having a lot of data in my data bank, the greater will be the time taken for the function to return a valid value.


At this time I need my script engine expect to be able to make a correct verification of returns.


However, as I said above. It does not seem very efficient while using the way you mentioned.

Last edited by NeoNeper; 10/23/13 14:40.

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: Ch40zzC0d3r] #431770
10/23/13 14:44
10/23/13 14:44
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: Ch40zzC0d3r
I wont wait for a return value too, thats why I said change the code in the dll, but if he cant thats a way I would use.

I tried to explain several times. This way cannot work and it does not.

Either the dll function is blocking. Then the engine won't proceed until that function has returned anyway and it's nonsense to wait. Or the dll function is not blocking. Then you need to call an additional function that checks if there is anything in progress or you need to pass an address to the function where a result can be stored and have to check if the content of that address is changed. But it won't work with return values the way you want to do it here.


Always learn from history, to be sure you make the same mistakes again...
Re: Questions about: How to create a macro function? [Re: Uhrwerk] #431784
10/23/13 19:01
10/23/13 19:01
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
So much head desk in here, I don't even...
Uhrwerk, thanks for your patience, I would have lost it already here...

Quote:
Well if you do network stuff you HAVE to wait because your internet is not as fast as your CPU.

In which case the DLL function wouldn't be blocking anymore, but asynchronous. You can't just decide to wait one frame and then be sure that the data arrived, networks are unpredictable. When you have an asynchronous function, you wait for a notification, normally using a callback. In any case though, the returned value from the function will not EVER change at all. It's a local variable, the callee has no way to return multiple values to the callee, or update the returned values. This isn't functional programming here.

In any case though, if Neos problem is fixed with a wait_for, than his stuff is seriously broken. wait_for() doesn't fix the problem, it just masks it. It's hard to tell what is going on, because we don't see what sql_select() does, but since it's a DLL method we can, with 100% certainty conclude that in no way does it call wait(). Also, if it did, it wouldn't return anything since wait() doesn't allow to return values to the caller.

So, to recap: Neos DLL function IS blocking. It can't call into wait(), so upon its return, it is done. If Neo kicks of an asynchronous task in the DLL function, than wait_for() won't help him wait for the results, since, again, the DLL function is done!

Both of you, please read up on how normal code execution flow works. Stuff doesn't just magically happen concurrently so that you have to synchronize it, and even if it did, wait_for() is the tank-through-the-door-instead-of-using-the-key approach of synchronization.


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: Uhrwerk] #431793
10/23/13 23:23
10/23/13 23:23
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Now I understand about how it works and how to proceed with the function wait.
At the end of the topic was directed to a very interesting question to me.

Could you please exemplify me, that way I could then receive values ​​that are being returned through the functions in the DLL without running the risk of a return check invalid?

Sample:
C++
Code:
DLLFUNC char* sql_get_select(char* buffer, char *column, int row)


DLL in C + +, this function will search from a list previously set, the values ​​that match the parameters sent by the function.

Sample in C++

Code:
...
DATA tempdata;

     for(ping =0; ping < MYDATA_INDEX; ping ++)
     {

          if(strcmp(column,MYDATA[ping].name)==0) //found an index in the local struct with the same name searched by the function
          {
            tempdata = &MYDATA[ping];
            if(tempdata->varchar.size())
            {
              strcpy(buffer,tempdata->varchar[row].c_str());
            }
           
           break;
          }

     }
...
return buffer;






IN LITE C

Code:
char buffer[256];
   for(int a = 0; a < 10; a++)
   {
      sql_get_select(buffer, "name", a);
      strcpy(LOCAL_TEST[a].name,buffer);
      .....
      //Note that my function must first find a result in a list in DLL and only then will return a correct value. Here I am running the risk of the not receiving a value on time
   }




I appreciate your attention

Last edited by NeoNeper; 10/23/13 23:27.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Page 2 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