Question on Script Operations
HegemonKhan
28 Jun 2014, 20:15if I have a looping 'changed' script, which is dependant upon other 'changed' scripts' adjustment to attributes, do I need to force invoke these other 'changed' scripts before I do the loop code line (via on ready), or will there not be any conflict~problem, as the other 'changed' scripts will be run and finish before the looping 'changed' script gets to it's part where it needs the other 'changed' scripts to have adjusted attributes?
and, another question that is apart of the above, which I don't even know about either, laughs
Are the other changed scripts even activated~executed (automatically; non-forced; non-coded into 'changed1' script), while the current 'changed1' script is still executing (due to its looping) ?
------------
forgot to mention this too (just in case it's not assumed'able, lol):
changed1 script
-> // changes the attribute of 'changed2attribute'
-> // changed2 script changes the attribute of 'changed3attribute'
-> // changed3 script's newly adjusted attributes (within its scripting) are required for changed1 script's looping
-> // looping code line (invoke changed1)
-------------
my changed1's looping execution is dependant upon the newly adjusted attributes from changed2 and changed3
so...
do I need to do this?
or can I just do this?
(if this isn't detailed enough for answering, I'll work on trying to post my code up for you to see what I'm talking about and trying to do exactly, though at the moment, I'm unable to post my code, which is why I'm trying to ask my question in this way, but it might not be enough info for you to answer it without me providing my code, as it'd be too difficult for me to try to explain more without my code to help, as explaining things is hard for me)
and, another question that is apart of the above, which I don't even know about either, laughs
Are the other changed scripts even activated~executed (automatically; non-forced; non-coded into 'changed1' script), while the current 'changed1' script is still executing (due to its looping) ?
------------
forgot to mention this too (just in case it's not assumed'able, lol):
changed1 script
-> // changes the attribute of 'changed2attribute'
-> // changed2 script changes the attribute of 'changed3attribute'
-> // changed3 script's newly adjusted attributes (within its scripting) are required for changed1 script's looping
-> // looping code line (invoke changed1)
-------------
my changed1's looping execution is dependant upon the newly adjusted attributes from changed2 and changed3
so...
do I need to do this?
<attr name="changed1" type="script">
// if...
// invoke (changed2)
// on ready
// invoke (changed3)
// on ready
// invoke (changed1)
</attr>
or can I just do this?
<attr name="changed1" type="script">
// if...
// invoke (changed1)
</attr>
(if this isn't detailed enough for answering, I'll work on trying to post my code up for you to see what I'm talking about and trying to do exactly, though at the moment, I'm unable to post my code, which is why I'm trying to ask my question in this way, but it might not be enough info for you to answer it without me providing my code, as it'd be too difficult for me to try to explain more without my code to help, as explaining things is hard for me)

jaynabonne
28 Jun 2014, 22:18It's really hard to say without seeing some real code. The problem with what you have shown is that there's no place in the code that exits the script (e.g. some form of get input/show menu/pause/etc). That would cause an infinite loop, which would make Quest lock up. A Quest script has to exit at some point so the engine can move on. If you never exit a script, then it can't run.
I also can't see how "on ready" would do anything for you, as they only have an effect with something like "ask" or "get input". They put off script execution until the "ask" or "get input" is done. If you don't have something like that, then an "on ready" will do nothing for you. So once again, perhaps more fleshed out code would show what you're really trying to do.
To perhaps answer what you're asking, a "changed" script is invoked after the new attribute value has been set, and it happens right at the time that value is set. So if you have a line like:
and you have a "changed" script on that attribute and it changes other values that have other "changed" scripts, then they will all be executed directly when their values are set, and everything will be settled by the time "some other script lines" are executed above. Nothing will be left pending. Hope that helps!
I also can't see how "on ready" would do anything for you, as they only have an effect with something like "ask" or "get input". They put off script execution until the "ask" or "get input" is done. If you don't have something like that, then an "on ready" will do nothing for you. So once again, perhaps more fleshed out code would show what you're really trying to do.
To perhaps answer what you're asking, a "changed" script is invoked after the new attribute value has been set, and it happens right at the time that value is set. So if you have a line like:
attribute = newValue
// some other script lines
and you have a "changed" script on that attribute and it changes other values that have other "changed" scripts, then they will all be executed directly when their values are set, and everything will be settled by the time "some other script lines" are executed above. Nothing will be left pending. Hope that helps!
HegemonKhan
29 Jun 2014, 02:14I'm working again on date and time coding, and I'm trying to code in adding months based upon added days, so there's the problem of (not my actual code yet):
january = 31 days
february = 28 days
march = 31 days
day = 1 (1st of january)
if: day = day + 90
I need to code for it being still march (the 31st)
vs
if: day = day + 91
I need to code for it being april (the 1st)
as the different # of days for the various months makes it a bit more complicated
so, to deal with this, I do looping and a stringdictionary that gets the month for what day it is, so I need to make sure that the script will update the day #, before the stringdictionary runs (and to deal with the differing months' days #s, I subtract that month's day # before I loop it)
----------
err, this is hard to hard to explain, and probably harder for you to understand, laughs. I'll get my code up as soon as I can do so.
----------
off of memory, so not fully exact...
january = 31 days
february = 28 days
march = 31 days
day = 1 (1st of january)
if: day = day + 90
I need to code for it being still march (the 31st)
vs
if: day = day + 91
I need to code for it being april (the 1st)
as the different # of days for the various months makes it a bit more complicated
so, to deal with this, I do looping and a stringdictionary that gets the month for what day it is, so I need to make sure that the script will update the day #, before the stringdictionary runs (and to deal with the differing months' days #s, I subtract that month's day # before I loop it)
----------
err, this is hard to hard to explain, and probably harder for you to understand, laughs. I'll get my code up as soon as I can do so.
----------
off of memory, so not fully exact...
<attr name="month_integer_to_day_integer" type="simplestringdictionary">1=31;2=28;3=31;4=30;etc</attr>
// I know I'm missing the attached object for my attributes, but I don't want to write more than I need to, so I'm leaving it off, but I'm fully aware I need to have an attached object for my attributes, I know I can't use variables across scripts (pretend that they have the attached object typed~coded in, that they are attributes and not variables, lol).
day_integer = day_integer + x
// x would be whatever~any value plugged in for it
<attr name="changedday_integer" type="script">
if (day_integer > ToInt (month_integer_to_day_integer, month_integer)) {
if (day_integer / ToInt (StringDictionaryItem (month_integer_to_day_integer, month_integer)) > 1)
month_integer = month_integer + 1
// do I need to" invoke (changed_month_integer), or not?
invoke (changedday_integer)
} else if (day_integer / ToInt (StringDictionaryItem (month_integer_to_day_integer, month_integer)) = 1)
month_integer = month_integer + 1
}
day_integer = day_integer % ToInt (StringDictionaryItem (month_integer_to_day_integer, month_integer))
if (day_integer = 0) {
day_integer = ToInt (StringDictionaryItem (month_integer_to_day_integer, month_integer))
}
}
</attr>
<attr name="changedmonth_integer" type="script">
if (month_integer > 12) {
if (month_integer / 12 > 1) {
month_integer = month_integer + 1
invoke (changedmonth_integer)
} else if (month_integer / 12 = 1) {
month_integer = month_integer + 1
}
month_integer = month_integer % 12
if (month_integer = 0) {
month_integer = 12
}
}
</attr>

jaynabonne
29 Jun 2014, 07:44The answer to the question posed in your comment is "no, you don't have to". The changed script for the month attribute will happen automatically when you change the month attribute, even if you're already inside a changed script for the day.
However, the way you have your code written won't work. You loop advancing months but never actually update the day attribute. You need to update the day variable as you progress months; otherwise, the code will loop forever (day will forever be, for example, 32, and it will never satisfy a month's limit). The easiest way to do that, if the day value exceeds the current month's days, is to increment the month and then subtract the number of days in the old month from the current days value. That way the days value will decrease. (The months are "eating up" your days as you go along.)
You also don't need to differentiate between ">1" and "=1". It should be the same code. (And dividing and checking the int value seems a bit more awkward to me than simply seeing if the days value is greater than or equal to the month's number of days.)
Finally, your 0 check for days is a bit baffling to me. In that case, you set the days value to the number of days in the current month, which will simply satisfy your check for "=1" when the changed script kicks in, and it will continue to loop.
Assuming your day value ranges from 0 to days_in_month-1, then I think your days "changed" script can be as simple as:
If your day value is in the range 1-days_in_month, then change the ">=" in the above to ">". And keep in mind that with a a 1-based day value, you can't use mod (%) at all unless you normalize it down to 0 before and then back up to 1-based afterwards, which is a real pain.
When you go to code this, I would really recommend you put some "msg"s in the various change scripts initially to watch what it's doing (and you could actually have answered your own question that way!
) What you're doing is a form of recursion by updating the day attribute while you're in the process of updating the day attribute. It can be cool when it works, but it can be a headache if not understood well enough.
However, the way you have your code written won't work. You loop advancing months but never actually update the day attribute. You need to update the day variable as you progress months; otherwise, the code will loop forever (day will forever be, for example, 32, and it will never satisfy a month's limit). The easiest way to do that, if the day value exceeds the current month's days, is to increment the month and then subtract the number of days in the old month from the current days value. That way the days value will decrease. (The months are "eating up" your days as you go along.)
You also don't need to differentiate between ">1" and "=1". It should be the same code. (And dividing and checking the int value seems a bit more awkward to me than simply seeing if the days value is greater than or equal to the month's number of days.)
Finally, your 0 check for days is a bit baffling to me. In that case, you set the days value to the number of days in the current month, which will simply satisfy your check for "=1" when the changed script kicks in, and it will continue to loop.
Assuming your day value ranges from 0 to days_in_month-1, then I think your days "changed" script can be as simple as:
days_in_month = ToInt (StringDictionaryItem (month_integer_to_day_integer, month_integer)
if (day_integer >= days_in_month) {
month_integer = month_integer+1
day_integer = day_integer - days_in_month
}
If your day value is in the range 1-days_in_month, then change the ">=" in the above to ">". And keep in mind that with a a 1-based day value, you can't use mod (%) at all unless you normalize it down to 0 before and then back up to 1-based afterwards, which is a real pain.
When you go to code this, I would really recommend you put some "msg"s in the various change scripts initially to watch what it's doing (and you could actually have answered your own question that way!
