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

Little script help

Status
Not open for further replies.

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
I want to learn JASS from the ground, so I'm doing wyrmlords JASS beginner tutorial (thanks! It's awesome!) Hoever, I fail to make one of his challenges work... It's just some small shit, but I think I should learn everything I can :)

JASS:
function DivideNumbers takes integer n returns nothing
    local integer split
    local string number
    set split = 1
    loop
        if n / split = real then
            set number = (n / split)
            call BJDebugMsg(number)
            set split = split + 1
            
        else
            set split = split + 1
        exitwhen split > n / 2
    endloop
endfunction

I guess it has something with handling variables and adding math like the "/"s, I've just scripted in flash before, so I go after those rules :p
btw, what this function is supposed to do is to show all the numbers that can perfectly split the n integer in the chat.
thanks, /at
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
First: you can't use a type as an operator (eg real)
Second: You have to manually convert integers/reals to strings via I2S and R2S respectively
Third: you forgot your endif
Fourth: TriggerRegisterPlayerChatEvent is a seperate event; it doesn't go inside TriggerRegisterPlayerEvent.

Tip: you can initialize variables with values, eg local integer split = 1

Oh, and in the future, please post Jass questions in the Jass forum.
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Thanks for the answer, a little to anvanced for me tho :p
What exactly is I2S and R2S?
And about the real. What a wanted to do was to check if the value had any decimals, how to do that?
About the forums: "World Editor Help Zone
Need help with the world editor? Ask questions about triggers, spells, scripts etc" isnt that right? :p

Another thing, from the save tutorial:
Supposed to finish the spell. Will this work? (There are like 2 syntax errors, I think I know why)
JASS:
function Slash_Condition takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction
function Slash_Actions takes nothing returns nothing
 local unit caster = GetSpellAbilityUnit()          
 local location start_position = GetUnitLoc(caster) 
 local group enemies = CreateGroup()              
 local unit temp                                    
 local integer count = 5
 local location temp_loc
 local location caster_loc
 local real casterspeed = GetUnitMoveSpeed(caster) //If I use integer it just says "Can convert real to integer by some reason. 
 SetUnitMoveSpeed(casterspeed x 2) //what's left is to convert the                            
    call GroupEnumUnitsInRangeOfLoc(enemies, start_position, 500.0, null)
    loop
    set temp = FirstOfGroup(enemies)
    exitwhen temp == null or count == 0
    set caster_loc = GetUnitLoc(caster)
    if IsUnitEnemy(temp, GetOwningPlayer(caster)) then 
        set temp_loc = GetUnitLoc(temp)                
        call IssuePointOrderLoc(caster, null, temp_loc) //Is this the right command for the caster to move, not get teleported? Or is he supposed to get teleported? I don't get the spell :P
        if temp_loc == caster_loc then
            call UnitDamageTarget(caster, temp, 50, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
            call GroupRemoveUnit(enemies, temp)
            set count = count - 1
            SetUnitAnimation(caster, Attack)//what to write here? What's the name of the animation, tried alot.
            PolledWait(1) //or about how long the attack animation is
            ResetUnitAnimation(caster)
        endif 
    endif
        call GroupRemoveUnit(enemies, temp)
    endloop
    call IssuePointOrderLoc(caster, null, start_position)
endfunction
function InitTrig_Slash takes nothing returns nothing
 set gg_trg_Slash = CreateTrigger() 
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Slash, EVENT_PLAYER_UNIT_SPELL_EFFECT) 
    call TriggerAddCondition(gg_trg_Slash, Condition(function Slash_Condition))
    call TriggerAddAction(gg_trg_Slash, function Slash_Actions)
endfunction
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
ModuloInteger(divisor,dividend) or ModuloReal(divisor,dividend) return the remainders. You can also check it by if num == I2R(R2I(num)) then

Blarg, about the WEHZ description, I guess it needs to be updated -.-. There's also a readme saying not to post all of that stuff in the WEHZ, and rather in the Triggers&Scripts forums.

As for the errors...

-you seem to randomly forget to use 'call'

-you used x, should be *

-stuff like "attack" should be enclosed in quotes (a string)

-You forgot to specify what unit to set the move speed (of)
 

at

at

Level 4
Joined
Aug 18, 2007
Messages
88
Thank for both of the answers, and I see I did som (really) stupid mistakes in that spell. However, I found out that starting of with a halfcomplete spell is just weird, cause I don't even know what it's supposed to do, so I made one from scratch instead, just to try n learn the basics.
The Imba, FIRE BLAST! Aoe :p


JASS:
function BlastCon takes nothing returns boolean
    return GetSpellAbilityId() == 1337 //the ability ID  
endfunction

function BlastActions takes nothing returns nothing
local group enemies
local unit caster = GetSpellAbilityUnit()
local location casterloc = GetUnitLoc(caster)
local unit temp
 local effect fire = AddSpecialEffectLoc("boomeffect", casterloc) //Is this enough to make it show up?
    call GroupEnumUnitsInRangeOfLoc(enemies, casterloc, 500, null)
    loop
        exitwhen temp == null
        set temp = GroupPickRandomUnit(enemies)
        if IsUnitEnemy(temp, GetOwningPlayer(caster)) then
                call UnitDamageTarget(caster, temp, 40, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_FIRE, null)
        endif
        call GroupRemoveUnit(enemies, temp)    
    endloop
    call DestroyEffect(fire)
    set enemies = null
    set caster = null
    set fire = null   
endfunction

function Blast_Trig takes nothing returns nothing
    local trigger blast_trigger = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(blast_trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(blast_trigger, Condition(function BlastCon))
        call TriggerAddAction(blast_trigger, function BlastCon)   
endfunction
(I will write in the other forum next time, but since I already have a thread here....)
 
Status
Not open for further replies.
Top