Chaos 0 Posted September 26, 2006 In a eventhandler you cna only use the "_this" but i would like to hand over more parameters. Like a normal script start, like <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[parameter1,parameter2,parameter3 etc.] exec "script.sqs" Unfortunatly that doesn´t work with a global array because these parameters differ each time and i want the script to be used by many units that are even created by script later (some even randomly). This is my idea: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit addEventHandler ["hit",{[_this,option1,option2,option3] exec "script.sqs"}] I must give to the scirpt a local options - but when i starts in the scirpt the hint-message and i read "scalar bool array..." By that it seems impossible to make a hundred arrays so that every AI uses their own. So i can´t use a global variables and global arrays for my script. Knows anybody other way to solve this problem ? Share this post Link to post Share on other sites
macguba 0 Posted September 27, 2006 These might help:- Online comref at OFPEC with useful link. Scripting topic eventHandlers, also on online comref. although I suspect you may know about them and the problem is more advanced than that... Share this post Link to post Share on other sites
Guest [B.B.S.] T_D Posted September 28, 2006 I think the error is in the script and not the execution so you should show us your script. Share this post Link to post Share on other sites
General Barron 0 Posted October 10, 2006 Sorry I don't have time to make a proper post but you need to use the 'format' command to dynamically change the code issued to the eventhandler. Example: player addeventhandler ["hit", format["(_this select 0) setdir %1", getdir player] ] This is a non-sense example, but what it does is this: When the eventhandler is added to the player, it 'types' the direction the player is facing at that moment into the EH code. For example, the player is facing 30 degrees when the EH is added. From then on, whenever the player is hit (i.e. the EH code is triggered), the player will be set to face 30 degrees. If you ran the mission again and the player was facing 90 degrees when the EH was added, then the player would be faced to 90 degrees whenever he is hit. You can only 'type' specific data types into code this way: numbers, bools, sides, strings, and arrays containing those types (not objects or groups). If you don't understand why, look what happens when you 'print' out a variable using format: hint format ["%1", my_variable] For some data types, the text that is printed out is the same as the text you type into a script (for example, a variable holding the number 1 will print out '1', the same thing you type into a script to refer to the number 1. A variable holding the player will print out something like 'west alpha black', which is not what you type into a script to refer to the player). That was much longer than I meant to type, and I'm sure it doesn't make much sense. But the idea is you are using the 'format' command to dynamically write your code into the script after the mission starts. Share this post Link to post Share on other sites
Chris Death 0 Posted October 10, 2006 hmm GB i just woke up so my eyes are too little at the mo to follow you Nah, i had just a few weeks ago troubles with a respawn script and a killed eventhandler so that i can follow you. Chaos - your problem is that the script has lost relation to one of your variables, therefore you get the scalar bool error. With using the format technique, you can avoid that. It's not impossible to add more than _this parameter to eventhandlers. Post your script and post what your option1-3 are and how you get to them. ~S~ CD Share this post Link to post Share on other sites
UNN 0 Posted October 10, 2006 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player addeventhandler ["hit", format["(_this select 0) setdir %1", getdir player]] That will only apply the direction the player was facing when the event handler was added, not the direction the player was when hit. The parameter your adding is a fixed constant. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">With using the format technique, you can avoid that. It's not impossible to add more than _this parameter to eventhandlers. Yeah you can add as many parameters as you want, although they have to be global variables, or at least values available globaly or constants. Although all of this is going to be acient history once you know what arrives. Share this post Link to post Share on other sites
General Barron 0 Posted October 12, 2006 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player addeventhandler ["hit", format["(_this select 0) setdir %1", getdir player]] That will only apply the direction the player was facing when the event handler was added, not the direction the player was when hit. The parameter your adding is a fixed constant. Um, yeah, that's what I said . I guess I didn't explain myself very well, but I was rushed . Anyway it is tough to follow what I've written, but it uses the same principles that are used to dynamically name global variables, if you've seen that done before. It's a very powerful and handy trick. I got halfway thru a tutorial on the subject quite a while ago... maybe I'll finish it off sometime. Share this post Link to post Share on other sites
UNN 0 Posted October 12, 2006 Quote[/b] ]I guess I didn't explain myself very well, but I was rushed Obvioulsy not in as much of a rush as I was Sorry, I did not read your entire post. There is another example here using global arrays and constants: Global Arrays & Event Handlers Share this post Link to post Share on other sites