|
skrot Beginner
Joined: 12 Mar 2012 Posts: 23
|
Posted: Wed Mar 21, 2012 8:08 pm
Problem with variables - Disappearing and reappearing values. |
Hello!
I am having some issues with my variables. All of them seem to loose their value for a few ms every now and then. Then problem is, when I'm evaluating an IF statement, this can ruin everything.
An example for the issue I am having:
#if ((@healthperc<40) || (@staminaperc <20)) {#say P - first true - @healthperc @staminaperc} {#say P - first false - @healthperc @staminaperc}
#if ((@healthperc<40) || (@staminaperc<20)) {
#if ((@healthperc<40) || (@staminaperc<20)) {#say second true - @healthperc @staminaperc} {#say second false - @healthperc @staminaperc}
*something here*
}
} {#NOOP}
Alright, so what this does: Check whether healthperc or staminaperc under a specific value. If at least one of them is, it says true/false and value of the variables.
Next line, same variables, same check, enters the next block only if it is true, else {#NOOP}.
Next line checks again, same as the first line. rest isn't important.
Problem is what I receive in my window:
P - first false - 100 100
second false - 100 100
The 2nd line should not even appear, because the previous statement should not have been evaluated as true. After a while my command line doesn't accept any alias, only if I send them with #EXEC.
Another extreme:
#if ((@healthperc<40) || (@staminaperc<20)) {#say second true - @healthperc @staminaperc} {#say second false - @healthperc @staminaperc}
What I receive:
second true - 84 77
Note: This block is within an alias which is looping until a a statement is true.It may loop for a very long time (0-2+ hours). the no-value periods reach such a time frame over time that I can notice the variable go blank on my status window.
Note: Version 3.34 |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Mar 21, 2012 11:18 pm |
Could you please actually cut and paste the entire relevant section of code within [code]...[/code] markers? Something is clearly missing because it looks like the last "} {#NOOP}" is not part of any of your #IF statements. The {} braces don't match. It is impossible to tell whether you have an error in your code.
Are there other scripts which are setting @healthperc and @staminaperc? Are those scripts running in separate threads? If so, you could very easily have thread conflict. When writing code that runs in separate threads, it can take some care to keep the threads from conflicting. You may want to study the documentation for #WAIT, #SECTION, and Threads. Without a great deal more information about all of your code, we can't give much help to make it thread-safe. |
|
|
|
skrot Beginner
Joined: 12 Mar 2012 Posts: 23
|
Posted: Wed Mar 21, 2012 11:48 pm |
Oh, I am sorry, I probably left in an extra } after cutting out the irrelevant loop part. My bad.
Code: |
#if (@turnedon) {
#if (@healthperc<40 || @staminaperc<20) {#say first true - @healthperc @staminaperc} {#say first false - @healthperc @staminaperc}
#if (@healthperc<40 || @staminaperc<20) {
#if ((@healthperc<40) || (@staminaperc<20)) {#say second true - @healthperc @staminaperc} {#say second false - @healthperc @staminaperc}
nextthingtodo sleep
#loop (10) {#if (@sleeping==0) {#wait 500} {#NOOP}}
} {#NOOP}
**other stuff, irrelevant to the part above**
} |
I am updating the Healthperc and staminaperc variables every time the mud sends relevant information.
I did not start a new thread (intentionally, maybe I should have?) for the alias, which runs the code above.
Also, I mentioned in the first post that after a period of time, my command line refuses to react to normal way of sending commands. I have to use #exec <command> to make them work. Aliases are not turned off, nor triggers.
Also, would this problem cause ALL my variables to go blank at the same time (for a few ms only)?
Thank you for your first response, I'm awaiting for what you have in mind after reading this!
(meanwhile I'm going to dig into threading, as I'll probably need it now or very soon.)
Update: Threading the looping alias seems to work wonders. Thank you for bringing that to my attention. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Mar 22, 2012 1:25 pm |
Any time you use #WAIT, #WAITFOR, #WAITSIGNAL, etc., you are creating a new thread which runs in the background. I think you must have been using threads if this alias was "looping until a a statement is true" as you said. Whenever you start using threads, you have the potential for collisions, where different pieces of code are trying to set or get the value of the same variable.
You say "threading the looping alias seems to work wonders". What do you mean by that? Do you mean you inserted a #SECTION command?
Use of #SECTION commands is good for preventing other threads from changing variables when you don't want them changed. But you also have to be careful not to put too much of your code inside #SECTION. Whenever a bit of code inside #SECTION is running, no other threads can run. Essentially, it temporarily halts threading so only the one bit of code is running. If you use it more often than you need, you end up eliminating all the advantages of threading, and potentially prevent other parts of your code from ever running. |
|
Last edited by Rahab on Thu Mar 22, 2012 1:30 pm; edited 1 time in total |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Mar 22, 2012 1:29 pm |
Oh, by the way, you don't need to use a #NOOP for your FALSE command statements. Simply drop the FALSE command statement completely. The FALSE statement is optional. Both of these syntaxes are valid:
Code: |
#IF (test statement) {TRUE command statement}
#IF (test statement) {TRUE command statement} {FALSE command statement}
|
#NOOP that was used in Zmud for certain things; it is retained in Cmud only for backward compatibility. There should never be a need for #NOOP in Cmud. |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|