BadgeService

Provides the ability for users to obtain badges or to view badge information.

# Methods

[{"index":"boolean AwardBadgeAndWait(string userId, string badgeId) (ServerOnly) (Yield)","0":"Gives badges to users and returns whether badges are successfully given or not. Script executions are suspended during the operation. Badges that cannot be given in the Maker environment can be given for testing purposes."}]

[{"index":"BadgeInfo GetBadgeInfoAndWait(string badgeId) (Yield)","0":"Acquires the badge information. Script executions are suspended during the operation. In the release environment, it can obtain the badge information in Waiting, Ing, and End statuses. In the maker environment, it can obtain the badge information in Register, Waiting, Ing, and End statuses."}]

[{"index":"void GetBadgeInfoAsync(string badgeId, func callback)","0":"Acquires the badge information. This operation is performed asynchronously, and the results can be retrieved with the specified callback. The first parameter of the callback is the badge's Id, and the second one is the badge's information. In the released world, it can obtain the badge information in Waiting, Ing, and End statuses. In the world still in progress, it can obtain the badge information in Register, Waiting, Ing, and End statuses."}]

[{"index":"BadgeInfoPages GetBadgeInfosAndWait(table badgeGrades, BadgeStatus badgeStatus) (Yield)","0":"Obtains an entity that can check the information of badges matching the search condition. Script executions are suspended during the operation. Searches the badges of all classes when designating nil to badgeGrades and searches the badges in all statuses that can be searched when designating nil to badgeStatus. The release environment allows the search of badges in Waiting, Ing, and End statuses. In the world still in progress, allows the search of badges in Register, Waiting, Ing, and End statuses."}]

[{"index":"boolean UserHasBadgeAndWait(string userId, string badgeId) (Yield)","0":"Checks if the user has a badge. Script executions are suspended during the operation. In the World you're creating, you start with no badges."}]

[{"index":"void UserHasBadgeAsync(string userId, string badgeId, func callback)","0":"Checks if the user has a badge. This operation is performed asynchronously, and the result can be received with the specified callback. The first parameter is the user's Id, the second is the badge's Id, and the third is whether the user has the badge. In Worlds in progress, there will be no badges initially."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Examples

#### GetBadgeInfosAndWait

You can search for badges that meet your conditions. The BadgeInfoPages type Entity returned by this function allows you to obtain the results by dividing them into pages when there are many search results.
    
    
    @Component
    script BadgeGradeSearcher extends Component
        method void SearchAvailableNormalRareBadges()
        -- Searches for available badges that are normal and rare rarity.
        local pages = _BadgeService:GetBadgeInfosAndWait({BadgeGrade.Normal, BadgeGrade.Rare}, BadgeStatus.Ing)
    
        while true do
        	local pageDatas = pages:GetCurrentPageDatas()
    
        	for _, badge in ipairs(pageDatas) do
        		-- Information of the searched badge
        		log("Badge Id: " .. badge.Id .. " Name: " .. badge.Name .. " Grade: " .. tostring(badge.Grade))
        	end
    
        	if pages.IsLastPage then
        		break
        	end
    
        	pages:MoveToNextPageAndWait()
        end
        end
    end
    

# SeeAlso

  * [Badge Management](/docs?postId=663)
  * [Badge Registration](/docs?postId=656)
  * [Using Badge Service](/docs?postId=664)