Couple things:
- Your error message is related to the fact you're trying to pass a function as a variable value. Use a temporary variable, and:
Set angleY To GetStartingAngle YSetAngle Y angleY
That'll make the compiler happy.
Second, while the Quintus' script is shorter, it's in terrible form. Using button and OnActivate as branches of a single if/elseif is just asking for trouble. That's why I set mine up the way I did. While that version may work (for the moment), it will cause problems if you try to change it much or need to expand on it in the future.
In particular, using button as both a input-tracking and state-tracking variable is a bad idea. In the menus (pause, options, etc) and dialogue, GetButtonState can return seemingly random results. Certain menus don't trip MenuMode (pause, IIRC).
In addition, the button is never reset properly. If the player escapes the messagebox, the script may continue checking what the value is long after the box is gone. If the player enters menu mode, picks an option, then leaves, the script will similarly break and enter an infinite loop (until it picks up the input from a
different messagebox and will position you in the house the next time a mod pops a message). All in all, I wouldn't use it. It may work, but it smells of bad code.
begin aiy_doorbell_scriptShort controlvarShort button; all variables MUST be declared at the top of the scriptFloat timerFloat swingTimeFloat swingSpeedFloat startAngleif ( MenuMode ) ReturnendifDontSaveObject; we can optimize here by only setting these two when they haven't been set yet.; since we set both at the same time, if one hasn't been set, neither haveif ( swingTime != 1 ) set startAngle to GetStartingAngle, y set swingTime to 1endif; using a GetDistance "player" check might skip this part sometimes, but GetDistance is *the slowest* function in the language; use it sparingly, if at all. you could try checking every couple seconds or every couple frames, but it doesn't matter too much.set timer to ( timer + GetSecondsPassed );rotate forward if ( timer < swingTime ) Rotate y, 2 ;rotate backward elseif ( timer < (swingTime * 3) ) Rotate y, -2 ;forward again elseif ( timer < (swingTime * 4 ) ) Rotate y, 2 ;reset timer back to zeroelse set timer to 0 ;set startY To GetStartingAngle Y ; this check is already done (right after DontSaveObject) SetAngle Y startAngle endif; using a separate, safe control variable and button variable is Good Form. You're unlikely to run into any problems this way, and its not sketchy.if ( controlvar == 1 ) set button to GetButtonPressed if ( button == -1 ) return elseif ( button == 0 ) "player"->PositionCell posX posY posZ rotationZ "Unim's House - Interior" ;you need to position the player (otherwise the doorbell will move), and give coordinates for where they should go set controlvar to 0 else ;use else here, just in case something funny happens set controlvar to 0 ;make sure to properly, explicitly reset button no matter how you leave the loop! Quintus' example had a few ways this might not happen return endifelse if ( onactivate ) ; put onActivate here to save time, if the messagebox is up, we don't need to worry about activation PlaySound "Sixth_Bell" MessageBox "Come in?", "Yes", "No" Set controlvar to 1 endifendifend
Now, that should be more reliable and more optimized. It should also be easier to understand and expand on later (if you need to). There wasn't much technically wrong with Quintus', but it wasn't the most reliable way to handle this. I don't have the CS here, so that might not compile, just post any errors you run into.
And the posX, posY, posZ, rotationZ values should be replaced with the values of the door marker (position and rotation Z).
Also, I noticed you're using a lot of tabs in the line. Use tabs at the beginning of the line for indenting only. Tab and space are different characters, and while MWScript probably won't complain, there's a lot of little things that can break a script. Just use a single space between parameters and functions and param lists.