• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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