Page 1 of 1

GetProcess issue

Posted: Sat Sep 28, 2019 11:58 pm
by ThisIsMe
So not sure where to put this but since it is a friendly advisory I thought I might post, if you are using GetProcess and running the core version built on or after 08-21-2019, there is an issue with GetProcess, I will splain.

Code: Select all

var pid := CInt(GetObjProperty(mobile, "#TimerControlPID"));
var process := GetProcess( pid );
In this example you have two variables, pid and process.

pid is looking to grab a cprop off the character, "#TimerControlPID" and using the CInt function will return the integer value of that cprop. Then you have process, which uses the GetProcess function to grab a script process using the pid variable. Simple and should work 100% of the time and it does, except what I can only speculate as unforeseen consequences have arisen!

In the event that in this case GetObjProperty does not find the "#TimerControlPID" property on the mobile and because it has been wrapped in the loving arms of CInt, the variable pid becomes equal to 0. When this is then passed onto GetProcess because pid is equal to 0, the GetProcess function returns the process id of the currently running script instead of an error or some other such nonsense.

I have written to Dev via Discord with the problem and while I am not too certain if my solution would be feasible, because GetProcess' default parameter of pid is equal to 0, in cases such as I describe above (and this was not a lone isolated instance mind you) instead of being equal to 0, it be changed equal to -1. This is generally what I do if I have a function with a default value on a parameter and I know the parameter would never be lesser than 0 and unfortunately or fortunately with the way CInt works, a failed conversion of an object returns 0, this could be something worth doing since CInt would be a much more laborious, tedious function to "fix" to change it's behavior. I am also speculating that a process id would or should never be lesser than 0 so at any rate, I leave you with this tale of woe and something new for the POL-Boffins to fix.

Re: GetProcess issue

Posted: Sun Sep 29, 2019 9:21 am
by Yukiko
This was an issue with a function in the timedScripts package in the Modern Distro which ThisIsMe found, and fixed. The timedScripts pkg is the core for all "buffs", for both the effects and the display of the icons.

I was trying to get poisoning to work property and I discovered that drinking a poison potion did nothing. After racking my brain trying to figure this out, I decided that a second set of eyes, and a second brain from a superior programmer would help. So I asked ThisIsMe for help. After finding the problem he was prompted to warn others by his post.

Re: GetProcess issue

Posted: Mon Sep 30, 2019 1:50 pm
by Nando
It should be fixed in the latest commit.

Re: GetProcess issue

Posted: Mon Sep 30, 2019 5:34 pm
by Yukiko
Thanks Nando!

Re: GetProcess issue

Posted: Sat Oct 05, 2019 6:58 am
by DevGIB
just as an idea aswell. the script should probably error check if the global prop exists.