LUA Unexpected Character Error

Defenestrator
New member
 
Posts: 2
Joined: Tue May 28, 2013 18:38

LUA Unexpected Character Error

by Defenestrator » Tue May 28, 2013 18:40

Hi, I'm new to these forums, but not to modding mt or to lua.
I'm currently hunting for an "unexpected character" near the comma on the last line.
Relevant code:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("cannon:cannon", {
    tiles={"cannon_cannon.png","cannon_cannon.png","cannon_cannon.png","cannon_cannon.png","cannon_cannon.png","cannon_cannon.png","cannon_front.png",},
    groups={cracky=1,level=3},
    paramtype2="facedir",
    on_rightclick=function(pos, node, clicker, itemstack)
        if (itemstack:get_name() == "cannon:ball_item") then
            if not minetest.setting_getbool("creative_mode") then
                itemstack:take_item()
            end
            local dir = node["param2"] / 4
            local obj = minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "cannon:ball")
            local shootdir = {x=0,y=0,z=0}
            local rotation = math.pi * (90 * dir) / 180
            if (dir == 0) then
                shootdir.y = 1
            else if (dir == 1) then
                shootdir.z = 1
            else if (dir == 2) then
                shootdir.z = -1
            else if (dir == 3) then
                shootdir.x = 1
            else if (dir == 4) then
                shootdir.x = -1
            else
                shootdir.y = 1
            end
            obj:setvelocity({x=shootdir.x*19, y=shootdir.y*19, z=shootdir.z*19})
            obj:setacceleration({x=shootdir.x*-3, y=-10, z=shootdir.z*-3})
            obj:setyaw(rotation + math.pi)
            minetest.sound_play("cannon_fire", {pos=pos})
            return itemstack
        end
    end,
})


Thanks,
Defenestrator
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Tue May 28, 2013 18:43

Sometimes when it says "unexpected character" it means something else, like (example) you typed "end" too many times or something.
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Tue May 28, 2013 18:53

Use elseif not else if
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Wed May 29, 2013 05:00

I get this kind of error when the encoding of my file is UTF-8 instead of ANSI :/
 

Defenestrator
New member
 
Posts: 2
Joined: Tue May 28, 2013 18:38

by Defenestrator » Wed May 29, 2013 16:59

Thanks sfan. I think that would be my error. I feel rather derp right now :P
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 11 guests

cron