Author Topic: how to: capture attempt to open door before it is opened?  (Read 2376 times)

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #45 on: September 03, 2010, 09:38:07 pm »


               My concern is not about with whether it's better to use OBJECT_SELF or an object variable (oDoor). My concern is that you should never use AssignCommand when your intention is to have the object running the current script run a simple command right away. Instead, you should simply call the function to run the command, in this case:

ActionOpenDoor(OBJECT_SELF)

Doing it using AssignCommand literally delays the execution of that code until after the current script is done, so there is extra overhead and absolutely no benefit. Even worse, doing this can lead to all sorts of other problems if one expect things to happen in the order they appear in the original script. In this particular case it might have worked just fine, but in many other cases it would have caused things to happen in the wrong order, causing problems that would be extremely hard to troubleshoot.

If the two techniques were roughly equivalent as far as the game engine is concerned, then it might not be a big deal. But as you can see, they actually do two very different things. You definitely should not defer execution of commands unless you have a reason to do so.
               
               

               


                     Modifié par Invisig0th, 03 septembre 2010 - 09:22 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #46 on: September 03, 2010, 10:23:10 pm »


               

Invisig0th wrote...

My concern is not about with whether it's better to use OBJECT_SELF or an object variable (oDoor). My concern is that you should never use AssignCommand when your intention is to have the object running the current script run a simple command right away. Instead, you should simply call the function to run the command, in this case:

ActionOpenDoor(OBJECT_SELF)

Doing it using AssignCommand needlessly delays the execution of that code until after the current script is done, so there is extra overhead and absolutely no benefit. Even worse, doing this can lead to all sorts of other problems if one expect things to happen in the order they appear in the original script. In this particular case it might have worked just fine, but in many other cases it would have caused things to happen in the wrong order, causing problems that would be extremely hard to troubleshoot.

If the two techniques were roughly equivalent as far as the game engine is concerned, then it might not be a big deal. But as you can see, they actually do two very different things. You definitely should not defer execution of commands unless you have a reason to do so.

This all you wrote are very relevant informations for beginning scripters, however delaing the function at the end of the script can be sometimes very good feature and its better used on OBJECT_SELF than any other object, also due to action queve.

Also there was issue where some function didn't worked without assigncommand (with any object, no matter if OBJECT_SELF). See here. Nobody yet brought explanation for this and I found another case with the same issue.
               
               

               


                     Modifié par ShaDoOoW, 03 septembre 2010 - 09:24 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #47 on: September 03, 2010, 10:29:03 pm »


               Thank you INVISIG0TH!!!!



I am VERY particular about code, absolutely fixated on doing it right, doing it with minimal commands, doing it clean. My own PW is over 1100 areas, runs lag free, crash free, [honest, I average ONE CRASH PER YEAR for the last 3-4 years] and has more numerous (sophisticated) systems than any other five servers combined (that I have seen).



My partner in code is just shy of her Masters Degree, a prodigy, she has been coding since 8 years of age, and now has over 22 years of experience. I am VERY lucky to pick her brain as I do. She tells me my code (though I am self taught largely over the last 35+years in several languages and scripts) is at a Masters Degree level. I tell you this because, though I may be blunt, even to the point of tactless, I earnestly TRY to tell it like it is... my speech is as direct as my code. I get a LOAD of flack for my efforts some times, and frankly it is undeserved.



I have a strange brain. I do not forget. It is bane and boon. I recall all the major details of every book I have ever read, even from my childhood.



If my posts are blunt, it is because I don't waste words. If I'm ever wrong, please do tell me, I can take it, but I assure you it is once in a very blue moon that I get called out on things. Like I said, I have a strange brain that does not loose details (like the rules for coding). Once I read it, it is in there. Not a photographic memory, that would be too easy, but one that is the proverbial elephant. Bane and boon.



Please people, remember, I am trying to help. It is the fool who kills the messenger.



Feel free to test me on this, visit my server and tell me you have not seen 10 wrongly configured servers for every system I have running like a dream.



Be well. Game on.

GM_ODA



aldohral.forumotion.com

66.232.100.90  CEP 2.1 or better required.
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #48 on: September 03, 2010, 10:31:28 pm »


               One other thing... the code in my examples of the correction above - I wrote that at the level most scripters could read here. There are large blocks of that thing where I can reduce 8-10 lines into 2 or 3, but you'd all have a hard time reading it that way. On my own server, we write even leaner than what you see here in my posts.

I can tell you the results you get by using AssignCommand incorrectly can cause lag and even crash your server in some cases.
               
               

               


                     Modifié par ehye_khandee, 03 septembre 2010 - 09:33 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #49 on: September 03, 2010, 10:46:21 pm »


               

ehye_khandee wrote...

I can tell you the results you get by using AssignCommand incorrectly can cause lag and even crash your server in some cases.

I would wonder, details, proofs...
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #50 on: September 03, 2010, 10:56:33 pm »


               

ShaDoOoW wrote...

ehye_khandee wrote...

I can tell you the results you get by using AssignCommand incorrectly can cause lag and even crash your server in some cases.

I would wonder, details, proofs...




Doubt if you please but you will have to create your own proofs. My experience comes from debugging other peoples' crashy modules by their request. Crashes and lag were common even after I fixed the obvious, digging deeper I found many systems that were doing the naughty AssignCommand with OBJECT_SELF - having cleared those, crashes vanished, lag dissipated (it was a largish module and PRC too). I no longer have the old buggy version and even if I did, it is not mine to give you as an example, but belongs to the authors who asked my help last year in fixing it.

Sorry I can't oblige your request.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #51 on: September 03, 2010, 11:12:42 pm »


               Interesting, but I don't think it really matters. It does not cause any problems or lag whatsoever in this script nor has using AssignCommand in many of the scirpts that I have used that function in, but thanks anyway.
Though if people are adamant against using it then by all means don't take my paltry skills at scripting as an indication you should do as I suggest. I have done it both ways and notice no difference. I suppose I could look at some of the other scripts where I use it, more complex examples, but I don't think it makes much difference, unless you were running in it a hb script.
               
               

               


                     Modifié par ffbj, 03 septembre 2010 - 10:13 .
                     
                  


            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #52 on: September 03, 2010, 11:18:37 pm »


               

ShaDoOoW wrote...
however delaing the function at the end of the script can be sometimes very good feature

Yes, I already said that.

Invisig0th wrote...
You definitely should not defer execution of commands unless you have a reason to do so.

Obviously if you have a reason to use this technique, then it would be a good reason and a good feature.

Regardless, it is very clear that no one in this thread was deliberately using this "feature" in an attempt to execute things after the script was finished. So that's not relevant to this discussion.
               
               

               


                     Modifié par Invisig0th, 03 septembre 2010 - 10:19 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #53 on: September 03, 2010, 11:29:58 pm »


               Actually it is because that is what I wanted, though more by chance than by design since I was basing off another script I made with similar use of AssignCommand.  But in most situations it is better to do as you and the Lexicon say.  Probably would have been fine too just have the door open itself.



               
               

               
            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #54 on: September 03, 2010, 11:33:08 pm »


               ffbj,

Fair enough, seems reasonable. Using the AssignCommand on OBJECT_SELF may be useful in some situations, but I think we can all agree that would be an advanced maneuver!
               
               

               


                     Modifié par Invisig0th, 03 septembre 2010 - 10:38 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #55 on: September 03, 2010, 11:34:49 pm »


               

ehye_khandee wrote...
Doubt if you please but you will have to create your own proofs.

Yes this won't please me, you are the accused side, not me, you are required to bring proofs. I have never seen lags or crashes due to assign command even delay commands. Yes some scripts may lag server, cep(1) torch heartbeat is good example how to not make scripts. Or if the script does TMI, it may cause big lagging after few runs.

But crashing? In past, it said that improperly used ActionEquipItem may crash the server but that was fixed long time ago, also too many bonus feats could cause crash - this was big PRC issue but it was fixed in 1.69 patch. Then adding too much spells into epic spell menu could crash too, but pardon me, I have never saw a beginner to make a script that could cause a crash and I don't believe you. I have seen a lot swashbucklers like you that claimed similar statements, but they never brought proof and I doubt you will.

That because if you could make a crash in script, this would be very useful feature for restarting server. AFAIK there isn't way, otherwise this would been common way to restart server already.

One more note for delaycommands. I have seen very poor ways to use them, for example the just in Hall of Fame spawn system (AmarAdam or similar) used (not sure if still uses) delay commands for every spawn waypoint that was in module. My friend have this in his module and it didnt lagged surprisedly. (But it threw TMI at on module load because the script tries to get all waypoints in module and run script on them - and my friend had like 2k these waypoints there)
               
               

               


                     Modifié par ShaDoOoW, 04 septembre 2010 - 12:01 .
                     
                  


            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #56 on: September 03, 2010, 11:36:30 pm »


               <sorry, duplicate post>
               
               

               


                     Modifié par Invisig0th, 03 septembre 2010 - 10:37 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #57 on: September 03, 2010, 11:42:49 pm »


               I don't know I would not call something a mistake that works. Sure it's not the prescribed method and the Lexicon says it pointless to do it that way, less efficient, whatever. But it works, nonetheless. As far as other situations go that is not relevant to this particular script, but like I said, don't do what I do, since clearly I don't know what I'm doing. Thanks for the input, all.
               
               

               


                     Modifié par ffbj, 03 septembre 2010 - 10:43 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #58 on: September 03, 2010, 11:44:58 pm »


               

ffbj wrote...

I don't know I would not call something a mistake that works. Sure it's not the prescribed method and the Lexicon says it pointless to do it that way, less efficient, whatever. But it works, nonetheless. As far as other situations go that is not relevant to this particular script, but like I said, don't do what I do, since clearly I don't know what I'm doing. Thanks for the input, all.

+1
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #59 on: September 03, 2010, 11:56:07 pm »


               I should probably use this opportunity to appologize to EK, who was correct is questioning me.  Initially I though he was saying I assigned assigncommand to OBJECT_SELF, and I was thinking, well clearly I defined oDoor as OBJECT_SELF.



Anyhow he. EK was correct when he said my comment was rude, and I think a bit mean, as in small of me, to say that, especially since he was right, but even if he was not right, that was inappropriate of me to say, so for that I appologize.