FAQ  •  Register  •  Login

Referencing Item IDs?

<<

furbuggy

Posts: 267

Joined: Mon Mar 08, 2010 5:34 pm

Location: Mesa AZ | Ithaca NY

Post Fri Jul 03, 2015 10:52 pm

Referencing Item IDs?

I figure that items have ID numbers now so that it is easier to reference them. Is there an easy way to do this in the code? For example, if I want a message "BOOM!" to appear when Core #1 falls to 0 hit points, how would I go about doing that? (lame example, but I figure a concrete piece of code would help)
BAM! I'm back.
<<

raptor

Posts: 1046

Joined: Mon Oct 11, 2010 9:03 pm

Post Sat Jul 04, 2015 8:16 am

Re: Referencing Item IDs?

We usually use 'events' to send messages to levelgens when certain things happen; however, there isn't one for when a core is destroyed. But, there is usually more than one way to do things when scripting is involved:

What I like to do is something like this. In main() in the levelgen, do:

  Code:
function main()
    bf:subscribe(Event.ScoreChanged)

    -- global object to keep track of the core I want, this can be used
    -- anywhere else in the script since it was declared in main()
    core1 = bf:findObjectById(1)
    core1destroyed = false
end

function onScoreChanged(scoreChange, teamIndex, player)
    -- If a score has changed, then some core must have been destroyed. 
    -- This is a workaround for missing onCoreDestroyed event
    if not core1destroyed then
        if core1 == nil or core1:getCurrentHealth() == 0 then
            core1destroyed = true
        end
    end
   
    if core1destroyed then
        -- Do something when core is destroyed
        levelgen:globalMsg("Core 1 was destroyed!")
    end
end
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Sat Jul 04, 2015 7:16 pm

Re: Referencing Item IDs?

<<

furbuggy

Posts: 267

Joined: Mon Mar 08, 2010 5:34 pm

Location: Mesa AZ | Ithaca NY

Post Thu Jul 23, 2015 3:14 pm

Re: Referencing Item IDs?

Oh wow! I didn't understand your response until now, thanks! That's very helpful.
BAM! I'm back.

Return to Levelgen Gallery

Who is online

Users browsing this forum: No registered users and 0 guests