Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 600 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
pointer in a function containig wait #472098
04/07/18 12:38
04/07/18 12:38
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline OP
Expert
alibaba  Offline OP
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
It's been some time since I've used 3DGS so it might be a stupid question.
(Code may contain errors since I've just typed from the top of my head)
Code:
void foo(int* i)
{
*i=5;
wait(1);
*i=6;
}

void main()
{
int a=0;
foo(&a);
wait_for(foo);
printf("%d", a);
}



This example gives me a "5" instead of a "6". Are pointers lost when using waits in a function? Is there a workaround?


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: pointer in a function containig wait [Re: alibaba] #472099
04/07/18 13:35
04/07/18 13:35
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
The problem is that wait_for sends the main() function into a wait state as well, of which you are aware, and then after wait_for a new variable with the same name and value is "allocated" (check their pointers with printf).
The solution or workaround rather is to better not use wait whenever you can in my opinion (or make it a global variable/ object if you have to).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: pointer in a function containig wait [Re: Superku] #472100
04/07/18 17:09
04/07/18 17:09
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
another workaround would be using dynamic memory allocation. still, like Superku said, avoiding wait as much as possible is probably the best way.


POTATO-MAN saves the day! - Random
Re: pointer in a function containig wait [Re: Kartoffel] #472104
04/08/18 14:47
04/08/18 14:47
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline OP
Expert
alibaba  Offline OP
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
Thanks for your answers. I think I'll go the global variable way. I need wait, because it's a heavy instruction, which needs some seconds and I don't want the game to freeze during that time.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: pointer in a function containig wait [Re: alibaba] #472105
04/08/18 15:10
04/08/18 15:10
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
You might declare that local variable as static variable too.

Re: pointer in a function containig wait [Re: txesmi] #472106
04/08/18 15:28
04/08/18 15:28
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline OP
Expert
alibaba  Offline OP
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
AH! How could I've missed that!? Thank you! It totally makes sense when reading Superkus and your answer.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de

Moderated by  old_bill, Tobias 

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