• 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.

How to write a code

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
JASS:
    //            call AddString(i + 20, "Level " + GetHeroLevel(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]) + " " + GetUnitName(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]))

Is current code, but it returns 20 errors.

AddString takes integer, string, player

How would i write this? I want the integer to be (this variable + 20), the string to be "Level " + "Level of Hero Variable[Number of Player]" + " " (space) + Name of[Hero Variable]
 
call AddString(i + 20, "Level " + GetHeroLevel(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]) + " " + GetUnitName(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]))

Let's break it down shall we?

Here are the 3 parameters you're passing:

i + 20
"Level " + GetHeroLevel(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]) + " " + GetUnitName(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]))

You're passing 2 parameters to a function that takes 3 parameters, and in the second parameter, you're concatenating a string with an integer (the hero level) with another string and another one.

The problem here is that you can only concatenate a string with another string.

That's why you should change your second parameter to this:
"Level " + I2S(GetHeroLevel(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())])) + " " + GetUnitName(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]))

I used the function I2S to convert from an integer to a string.
There are other functions like S2I, R2I, I2R, R2S, S2R and R2SW.
R = Real
S = String
I = Integer

R2SW converts a real to a string, but it also takes extra parameters that let you specify the accuracy of the real. (how many digits)

You're missing a third parameter (the player).

This is what your code should look like:

call AddString(i + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())])) + " " + GetUnitName(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())])), GetTriggerPlayer())
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
-.- Thanks, but it seems all the mistakes i made were noob that i just made because i wasnt paying attention. Good thing im not paid for this

Thanks

e/ unexpected: ","

2e/ extra )
 
Status
Not open for further replies.
Top