Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why is Attempt to get Length of a nil value Error in Line 52? How do I fix this?

Asked by 8 years ago

This isn't in Roblox, But I think you guys can Help me

-- A basic encounter script skeleton you can copy and modify for your own creations.

-- music = "shine_on_you_crazy_diamond" --Always OGG. Extension is added automatically. Remove the first two lines for custom music.
encountertext = "Papyrus is Paping :D!" --Modify as necessary. It will only be read out in the action select screen.
nextwaves = {"bullettest_bouncy"}
wavetimer = 4.0
arenasize = {155, 130}

enemies = {
"Papyrus The Unpaping"}

enemypositions = {
{0, 0}
}

-- A custom list with attacks to choose from. Actual selection happens in EnemyDialogueEnding(). Put here in case you want to use it.
possible_attacks = {"bullettest_bouncy", "bullettest_chaserorb", "bullettest_touhou"}

function EncounterStarting()
    -- If you want to change the game state immediately, this is the place.
end

function EnemyDialogueStarting()
    -- Good location for setting monster dialogue depending on how the battle is going.
    enemies[1].SetVar('currentdialogue', {"NYEHEHE!"})
end

function EnemyDialogueEnding()
    -- Good location to fill the 'nextwaves' table with the attacks you want to have simultaneously.
    -- This example line below takes a random attack from 'possible_attacks'.
    nextwaves = { possible_attacks[math.random(#possible_attacks)] }
end

function DefenseEnding() --This built-in function fires after the defense round ends.
    encountertext = RandomEncounterText() --This built-in function gets a random encounter text from a random enemy.
end

function HandleSpare()
     State("ENEMYDIALOGUE")
end

function HandleItem(ItemID)
    BattleDialog({"Selected item " .. ItemID .. "."})
end
animationFrames = {"poseur", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"}
currentFrame = poseur
animationTimer = 0

function Update()
    animationTimer = animationTimer + 1
    if(animationTimer%20 == 0) then
        currentframe = (currentframe % (#animationframes)) + 1
        animationTimer = 0
        enemies[1].SetSprite(animationFrames[currentFrame])
   end
end

3 answers

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
8 years ago

Typo: animationframes instead of animationFrames (note the capital F).

EDIT:

Looks like you also forgot to capitalize the F in currentframe on line 52.

ANOTHER EDIT:

I think you mean for currentFrame to start at 1, not poseur (which is a nil value).

Line 46:

currentFrame = 1
0
It didn't work, Now I am getting "Attempt to Perform Arithmetic on a nil value " christiannewman 0 — 8y
0
Updated. There was another error on your script. XAXA 1569 — 8y
0
Oh christiannewman 0 — 8y
0
Still won't work christiannewman 0 — 8y
View all comments (4 more)
0
You sure? What's the error so far? Remember that you misspelled currentframe twice in line 52. XAXA 1569 — 8y
0
Yes, I fixed it, the code is now: christiannewman 0 — 8y
0
I just put the new code in Answers, please help me christiannewman 0 — 8y
0
It is Attempt to Perform arithmetic on a nil value christiannewman 0 — 8y
Ad
Log in to vote
0
Answered by
Djinous 45
8 years ago

animationFrames isn't capitalized in line 52.

Log in to vote
0
Answered by 8 years ago
-- A basic encounter script skeleton you can copy and modify for your own creations.

-- music = "shine_on_you_crazy_diamond" --Always OGG. Extension is added automatically. Remove the first two lines for custom music.
encountertext = "Papyrus is Paping :D!" --Modify as necessary. It will only be read out in the action select screen.
nextwaves = {"bullettest_bouncy"}
wavetimer = 4.0
arenasize = {155, 130}

enemies = {
"Papyrus The Unpaping"}

enemypositions = {
{0, 0}
}

-- A custom list with attacks to choose from. Actual selection happens in EnemyDialogueEnding(). Put here in case you want to use it.
possible_attacks = {"bullettest_bouncy", "bullettest_chaserorb", "bullettest_touhou"}

function EncounterStarting()
    -- If you want to change the game state immediately, this is the place.
end

function EnemyDialogueStarting()
    -- Good location for setting monster dialogue depending on how the battle is going.
    enemies[1].SetVar('currentdialogue', {"NYEHEHE!"})
end

function EnemyDialogueEnding()
    -- Good location to fill the 'nextwaves' table with the attacks you want to have simultaneously.
    -- This example line below takes a random attack from 'possible_attacks'.
    nextwaves = { possible_attacks[math.random(#possible_attacks)] }
end

function DefenseEnding() --This built-in function fires after the defense round ends.
    encountertext = RandomEncounterText() --This built-in function gets a random encounter text from a random enemy.
end

function HandleSpare()
     State("ENEMYDIALOGUE")
end

function HandleItem(ItemID)
    BattleDialog({"Selected item " .. ItemID .. "."})
end
animationFrames = {"poseur", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"}
currentFrame = poseur
animationTimer = 0

function Update()
    animationTimer = animationTimer + 1
    if(animationTimer%20 == 0) then
        currentFrame = (currentFrame % (#animationFrames)) + 1
        animationTimer = 0
        enemies[1].SetSprite(animationFrames[currentFrame])
   end
end

0
Please don't put your current code into the answers. Anyway, what is the current error you are getting? XAXA 1569 — 8y
0
Attempt to perform Arithmetic on a nil value christiannewman 0 — 8y
0
Updated. XAXA 1569 — 8y
0
That is the Error christiannewman 0 — 8y
View all comments (3 more)
0
Now it is cannot access field SetSprite of userdata<ScriptWrapper> On Line 54 christiannewman 0 — 8y
0
Is there even a SetSprite function? XAXA 1569 — 8y
0
enemies[1].SetSprite christiannewman 0 — 8y

Answer this question