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

Why can't you call a number value?

Asked by
appxritixn 2235 Moderation Voter Community Moderator
5 years ago

I am writing a script to switch between pages for a Spell Book. When I try to switch pages, the code I think should work throws an error saying:

Players.smash1975.PlayerGui.SpellBook.RightFrame.Back.Handler:68: attempt to call a number value

The line which is throwing the error is:

1button.Parent.SpellsL.Text = getPage(page,0)

The function "getPage" is:

01function getPage(page,side)
02    if tonumber(page) >= -1000 then
03        -- Page is a number (Is hardcoded so always should be)
04        local p = pages
05        for x=1,#p,1 do
06            if side == 1 then
07                if p[x] == (page+math.floor(side)(page-1)) then
08                    -- Found correct page
09                    local ret = ""
10                    local c = p[x+1]
11                    for i=1,#c,1 do -- Convert list to string
12                        ret = ret..c[i].."\n"
13                    end
14                    return ret -- return string
15                end
View all 30 lines...

The error is being throw when I try to call "page" to alter the position in the list that I get the string from. (Line 7)

1
Originally, I did not separate the code into if side == 1 and else, but I was just trying to see if the value of 0 was the issue. It is not. appxritixn 2235 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

if p[x] == (page+math.floor(side)(page-1)) then

"page+math.floor(side)" is a number, by doing "(page-1)" it thinks you're trying to call it like a function but we know it's a number value. I'm not sure what you want to put inbetween there, or if you just forgot but it should look something like this.

1if p[x] == (page+math.floor(side)+(page-1)) then
0
I can't believe I didn't notice I was missing an operator. I feel like an idiot. appxritixn 2235 — 5y
0
It's okay, I'm just glad it works! CeramicTile 847 — 5y
Ad

Answer this question