View Single Post
Seren

JCF Member

Joined: Feb 2010

Posts: 872

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Mar 25, 2025, 01:59 AM
Seren is offline
Reply With Quote
Quote:
Originally Posted by jjturbo9 View Post
I wonder why you have to write player.xPos and player.yPos though. Seems irrelevant to me, what am I missing?
The main reason is that most people have two ears rather than one. Our brains like to believe every sound is coming from a point in space, and if that point is distant, the sound gets quieter, and if it's to our left, we hear it better with our left ear, etc. Most gaming computer setups support this notion by using audio output peripherals with at least two independent speakers, such as stereo headphones, but sometimes more, such as surround sound systems. For this reason, audio libraries allow you to precisely position the source of each sound in space, which in this case Violet guessed you'd want to be where the player is. You can imagine potentially manipulating this value to instead guide the player towards the direction where a door just opened.

Quote:
Originally Posted by jjturbo9 View Post
I just tried it but I don't hear the sound yet. To be extra clear about what I try:
When Jazz (or another) walks through the event 'Trigger Zone 21 | onoff 1 | switch 0' the sound COMMON_ITEMTRE has to be played. But only the first time he walks through it, I don't want the sound to trigger every time, only when the thing is triggered the first time. But I think that would be the case automatically anyways?
The scripting system is very powerful and could detect the player entering a trigger zone and doing everything you describe, but the code to do so would be more complicated than what Violet is suggesting. Violet's suggestion is to use a text event instead, which JJ2+ modifies such that, with the right parameters, it can directly trigger execution of user-defined AngelScript code specified by functions named onFunction0 through onFunction255. The details show up early in the introduction section of the AngelScript readme, which you mentioned you tried reading, so Violet might've assumed you would implicitly understand you have to change the event in the level too.

The code Violet sent says: "when onFunction0 is called, if trigger 66 is currently off, turn trigger 66 on and play this sound." So it encompasses the functionality of a trigger zone within it, meaning you can safely replace the relevant trigger zone in your level with a text event (text ID parameter should be 0 to call onFunction0, AngelScript parameter should be 1 to inform the event you're trying to execute a script function and not display text to the player). Note that, the way Violet formulated the script, the sound will indeed play only once, unless you later deactivate the trigger (e.g. by dying) and come back to activate it again, but it's definitely deliberate wording on her part and not "the case automatically."

Quote:
Originally Posted by jjturbo9 View Post
At least the original code still works even with this code in it, previously when I added non-working code the sugar rush counter stopped working too.
This is because this code is not erroneous, it just doesn't do anything unless the level contains the relevant text event. Your script will only fail to run wholesale if there's an error in it that makes the game fail to understand what you were trying to do. When this happens and AngelscriptDebug is enabled in your plus.ini, information about the error is printed to the chatlogger - it's a good setting to have enabled if you write scripts, the details again are mentioned in the introduction of the AngelScript readme.
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.