• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Problem with sound variable name?

Status
Not open for further replies.
Level 8
Joined
Mar 12, 2008
Messages
437
Alright, so I have a map where different random enemy creeps spawn periodically, and they have an individual "spawn call" which sounds as they spawn. The system works like this: every creep has an ID number (their point value), and I simply named every sound variable to the ID of the creep associated with it.

This little thing is what I want to do, but it's erroneous:
  • Custom script: call PlaySoundAtPointBJ( gg_snd_GetUnitPointValueByType(udg_Creep[udg_CreepNumber]), 100, udg_P[100], 0 )
CreepNumber is an integer variable. When a creep is to be spawned, this number is randomized.
Creep[X] is a unit-type variable, which returns the unit type whose point-value is X. (Example: if Footman has point-value 7, then Creep[7] = Footman. The Footman's associated sound is simply named "7")
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
You're trying to do the impossible (well, it's possible with textmacro's in vJass, but that aside).
You cannot use functions (such as "GetUnitPointValue") just wherever you want. Attaching a function to a variable name doesn't work.
The reasoning is very simple: it's expecting a variable name. Where does the variable name end and the function begin in your line (rhetorical question)? How is the editor supposed to know that?
Also, GetUnitPointValue returns an integer, not a string. If you wanted to use it, you'd have to convert it first :).


For Maker's suggestion, you need to create a variable called "SoundArray".
Then set them up in some init-trigger and then you can use his line :).
 
Level 8
Joined
Mar 12, 2008
Messages
437
I see, I suspected something in the lines of that. Do I manually have to set every sound, or could I use something that converts the integers into strings and use them to retrieve the sounds? Is it complicated to do that vJass thing?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I highly suggest using arrays over textmacro's :p.

A textmacro basically copy/pastes any code to where you want it. Here's a simple example:
JASS:
// This is the textmacro
//! textmacro PLAY_SOUND takes INT
    call PlaySoundAtPointBJ( gg_snd_$INT$, 100., udg_TempLoc, 0. )
//! endtextmacro

// This is how you run a textmacro
//! runtextmacro PLAY_SOUND("1")
So what this does is, it replaces "$INT$" with whatever you input between the brackets.
In this case, "gg_snd_$INT$" becomes "gg_snd_1". And this works: the sound plays correctly.

The problem is that I don't think you can use variables for gg_VAR_INTs (and I honestly don't know why :p).

This does work:
JASS:
//! textmacro PLAY_SOUND takes INT
    call BJDebugMsg( "Test: " + I2S($INT$) )
//! endtextmacro

// Inside a function:
set int =  GetUnitPointValue(udg_Unit) 
//! runtextmacro PLAY_SOUND("int")
So if I select a unit with point-value 2, it would display "Test: 2".
If I convert "int" to a string, that also works.

But when I try to use "gg_snd_$INT$", it breaks :/.


Anyway, even if you manage to get this to work: all it does is copy/paste the same code over and over again.
An array doesn't do that :D.

So, yeah, set the array manually and use Maker's line. It's better (and it actually works, which is a nice bonus).
 
Status
Not open for further replies.
Top