Tarlen
Tarlen

Reputation: 3797

Method is not defined error

I am trying to implement some private methods that cannot be called from the client, by defining them outside of the Meteor.methods scope, and under the server folder

I have this

Meteor.methods

    #
    # Generates a random event based on tags
    #
    generateRandomEventForCharacter: (characterId) ->
        character = Characters.findOne(characterId)
        rarity = randomRarity()

        # Tags
        locationTags  = ['all', character.location]
        alignmentTags = character.alignmentTags
        characterTags = character.characterTags

        event = Events.findOne( $and: [
            locationTags:  { $all: locationTags },
            alignmentTags: { $all: alignmentTags },
            characterTags: { $all: characterTags }
        ])

        return event

#
# Random rarity
#
randomRarity: () ->
    random = Math.random()

    rarity = switch
        when random < 0.005 then 'mythical'
        when random < 0.050 then 'epic'
        when random < 0.100 then 'rare'
        when random < 0.250 then 'uncommon'
        else 'common'

But somehow the following exception is thrown

Exception while invoking method 'generateRandomEventForCharacter' ReferenceError: randomRarity is not defined

Upvotes: 0

Views: 168

Answers (1)

Peppe L-G
Peppe L-G

Reputation: 8345

randomRarity: should be randomRarity =. Did the same mistake some days ago :)

Upvotes: 1

Related Questions