Mar 23, 2025, 05:40 PM | |
![]()
I'm trying to trigger a sound when the player walks into a certain tile. On the tile is a trigger zone event and I would like to trigger the sound COMMON_ITEMTRE when the players walks through the trigger zone, but only that particular trigger zone ID. I'm a noob with AS and programming in general, I tried to understand the AS readme, searched some threads, checked some code snippets from this site and looked how other users use AS in their levels but I still don't get it to work. I made the sugar rush counter code snippet from Bloody Body work with AS though so if I know the code I can do it.
Thank you very much in advance! |
Mar 24, 2025, 06:50 AM | |
This sounds like a perfect use case for an onFunction# hook, like
Code:
void onFunction0(jjPLAYER@ player) { if (!jjTriggers[66]) { jjTriggers[66] = true; jjSample(player.xPos, player.yPos, SOUND::COMMON_ITEMTRE); } } Code:
void onFunction0(jjPLAYER@ player, uint8 triggerID) { if (!jjTriggers[triggerID]) { jjTriggers[triggerID] = true; jjSample(player.xPos, player.yPos, SOUND::COMMON_ITEMTRE); } } |
Mar 24, 2025, 12:18 PM | |
Thanks a lot!! I will try this code now. I wonder why you have to write player.xPos and player.yPos though. Seems irrelevant to me, what am I missing?
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? I just copy/pasted the first code you send in my AS file where the other AS code already worked. And replaced 66 for 21, but when I trigger the thing I don't hear anything. I already checked if I wrote COMMON_ITEMTRE correctly and that's not the issue... Code:
//Sugar rush counter bool onDrawLives(jjPLAYER@ player, jjCANVAS@ screen) { screen.drawSprite(590, 45, ANIM::PICKUPS, 1, jjGameTicks>>2, -1, SPRITE::NORMAL); screen.drawSprite(580, 30, ANIM::PICKUPS, 13, jjGameTicks>>2, -1, SPRITE::NORMAL); screen.drawString(570, 15, "SUGAR RUSH", STRING::SMALL, STRING::PALSHIFT, 16); screen.drawString(600, 35, formatInt(player.food%100, "1") + " / 100", STRING::MEDIUM, STRING::PALSHIFT, 16); return false; } //Sound effect for getting key void onFunction0(jjPLAYER@ player) { if (!jjTriggers[21]) { jjTriggers[21] = true; jjSample(player.xPos, player.yPos, SOUND::COMMON_ITEMTRE); } } ![]() Last edited by jjturbo9; Mar 24, 2025 at 12:32 PM. |
Mar 25, 2025, 01:59 AM | |||
Quote:
Quote:
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." 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. |
Mar 25, 2025, 05:20 AM | |
Thank you Seren, I will try this later. I understand most of what you explained, and Violet's code makes sense now. But what do you mean with 'AngelScript parameter should be 1'. What exactly should I put to '1'? Ooo, wait.. I think I remember I saw an AngelScript parameter in the text event window, you probably mean that.... Right? Anyways, thanks!!
|
Mar 25, 2025, 05:29 AM | |
Wow, it worked now!! After you explained it I actually remembered reading something about this in the readme but didn't think of using it here like this. Anyways this is my working code now:
Code:
//Sugar rush counter bool onDrawLives(jjPLAYER@ player, jjCANVAS@ screen) { screen.drawSprite(590, 45, ANIM::PICKUPS, 1, jjGameTicks>>2, -1, SPRITE::NORMAL); screen.drawSprite(580, 30, ANIM::PICKUPS, 13, jjGameTicks>>2, -1, SPRITE::NORMAL); screen.drawString(570, 15, "SUGAR RUSH", STRING::SMALL, STRING::PALSHIFT, 16); screen.drawString(600, 35, formatInt(player.food%100, "1") + " / 100", STRING::MEDIUM, STRING::PALSHIFT, 16); return false; } //Sound effect for getting key void onFunction100(jjPLAYER@ player) { if (!jjTriggers[21]) { jjTriggers[21] = true; jjSample(player.xPos, player.yPos, SOUND::COMMON_ITEMTRE); } } |
Mar 25, 2025, 06:06 AM | |
Excuse me, initially I wrote this message to ask a question but I already found an answer while explaining the question in detail xD So there's no question here anymore except maybe what I asked at the end of this message, although it's not that important because the code works now.
. I decided I want the door to open when Jazz stands close to the door, as if Jazz opened the door with the key. Instead of opening together with getting the key. So I have to add another piece of code. Somehow it worked already with what I made up, but only because I made it simpler because I don't know how to code 2 'if' functions. I want the door to open when walking through text event 101 but only if you walked through text event 100 first. I wrote this: Code:
//Sound effect for getting key void onFunction100(jjPLAYER@ player) { if (!jjTriggers[21]) { jjTriggers[21] = true; jjSample(player.xPos, player.yPos, SOUND::MENUSOUNDS_TYPEENTER); } } //Door opening only if you have the key and go to door after void onFunction101(jjPLAYER@ player) { if (jjTriggers[21]) { jjTriggers[24] = true; } } Code:
//Sound effect for getting key void onFunction100(jjPLAYER@ player) { if (!jjTriggers[21]) { jjTriggers[21] = true; jjSample(player.xPos, player.yPos, SOUND::MENUSOUNDS_TYPEENTER); } } //Door opening only if you have the key and go to the door after + sound void onFunction101(jjPLAYER@ player) { if (!jjTriggers[24]) if (jjTriggers[21]) { jjTriggers[24] = true; jjSample(player.xPos, player.yPos, SOUND::COMMON_MONITOR); } } Last edited by jjturbo9; Mar 25, 2025 at 06:56 AM. |
Mar 25, 2025, 09:54 AM | |||
Quote:
Quote:
Code:
jjTriggers[21] and not jjTriggers[24] Code:
jjTriggers[21] && !jjTriggers[24]
__________________
I am an official JJ2+ programmer and this has been an official JJ2+ statement. |
![]() |
«
Previous Thread
|
Next Thread
»
Thread Tools | |
|
|
All times are GMT -8. The time now is 02:11 PM.
Jazz2Online © 1999-INFINITY (Site Credits). Jazz Jackrabbit, Jazz Jackrabbit 2, Jazz Jackrabbit Advance and all related trademarks and media are ™ and © Epic Games. Lori Jackrabbit is © Dean Dodrill. J2O development powered by Loops of Fury and Chemical Beats. Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Original site design by Ovi Demetrian. DrJones is the puppet master. Eat your lima beans, Johnny.