|
see if a text is still valid
#441715
05/31/14 20:43
05/31/14 20:43
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
In a while loop I want to see if a text is still valid. So far the only way I have found to see if this is true is with this
while(ptr_for_handle(handle(my_text)) != NULL)
ptr_for_handle is a medium speed function and if I can help it I do not want to use it in a while loop, handle says it is fast but that still seems like a lot of waster resources here.
(my_text) (my_text != NULL) do not work.
The text is removed with ptr_remove()
Any faster ideas then what I have tried?
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: see if a text is still valid
[Re: 3run]
#441718
05/31/14 20:57
05/31/14 20:57
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
ptr_for_handle(handle(my_text)) is pointless. It will crash if my_text is a vagabonding pointer.
The clean way is to set all pointers to a specific element to null. Then you can check in the other code if its valid (non-null) or removed (null).
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: see if a text is still valid
[Re: Uhrwerk]
#441722
05/31/14 21:47
05/31/14 21:47
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
When I set the my_text to NULL and in the other function check to see that it isn't null, the function doesn't end. I know this as I have sys_exit set after the function so it can't be missed.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: see if a text is still valid
[Re: FoxHound]
#441724
05/31/14 21:56
05/31/14 21:56
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Then you did something wrong in your code. Here is a working example for you:
#include <acknex.h>
TEXT* myText = NULL;
void waitForMyTextToBecomeNull()
{
while (myText)
wait(1);
sys_exit("e voila...");
}
void main()
{
myText = txt_create(1,1);
waitForMyTextToBecomeNull();
wait(-2);
ptr_remove(myText);
myText = NULL;
}
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: see if a text is still valid
[Re: Uhrwerk]
#441747
06/01/14 16:19
06/01/14 16:19
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
You're code does work, even when I pass the text pointer through the function. Prehaps my storing the text with handle has something to do with it. Here is the code that concerns this. ////////////////////////////// // this function checks to see if the var has changed, and if it has we alter the string in the text to match it ////////////////////////////// void monitor_for_var_change(TEXT* loc_text) { while(loc_text) wait(1);
sys_exit(""); }
Yes I Have made sure that skill_y holds the text. when the function runs the panel and the text both disappear. I simply need the function itself that checks for the text to end so I do not have pointer errors (I removed code that had nothing to do with the problem and I removed that from my own code to see if it might be the issue.
void destory_foxpan(PANEL* fox_pan) { TEXT* mytext = ptr_for_handle(fox_pan.skill_y);
////////////////////////////// // we remove the text ////////////////////////////// ptr_remove(mytext); mytext = NULL;
////////////////////////////// // we remove the panel ////////////////////////////// ptr_remove(fox_pan);
}
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: see if a text is still valid
[Re: FoxHound]
#441750
06/01/14 16:24
06/01/14 16:24
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
You're testing a local variable for a change. The local variable however won't change until you modify it in the corresponding function. You can either use a global variable instead or pass a pointer to the pointer to the function and check the variable this way.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: see if a text is still valid
[Re: Uhrwerk]
#441751
06/01/14 16:57
06/01/14 16:57
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
How am I using a local variable? I am assigning the pointer to a pointer and modifying it. This can be seen as when I destroy the text, it disappears from my screen.
If you can show an example of where I can keep the pointer in the skill of the panel and make this work it would be great, otherwise it seems a struct is my best hope.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: see if a text is still valid
[Re: FoxHound]
#441754
06/01/14 17:45
06/01/14 17:45
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Here is a working example for you that uses a pointer to the pointer:
#include <acknex.h>
void waitForThePointerToBecomeNull(void** p)
{
while (*p)
wait(1);
sys_exit("e voila...");
}
TEXT* myText = NULL;
void main()
{
myText = txt_create(1,1);
waitForThePointerToBecomeNull(&myText);
wait(-2);
ptr_remove(myText);
myText = NULL;
}
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: see if a text is still valid
[Re: Uhrwerk]
#441755
06/01/14 19:03
06/01/14 19:03
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
Still not working. However I did get it to work a different way by having the destory function set the skill_y of the text to 0 and tell the wait function to end if the skill y is zero. Not happy with it but it works.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
|