An error with my function`s registration

Post Reply
User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

An error with my function`s registration

by Andrey01 » Post

I`ve written function minetest.register_poisoning_effect() and here is an error:

Code: Select all

2018-04-23 23:02:44: ERROR[Main]: ModError: Failed to load and run script from /home/user/.minetest/mods/medicine/init.lua:
2018-04-23 23:02:44: ERROR[Main]: ...e/user/.minetest/mods/medicine/effects_and_illnesses.lua:1: '=' expected near 'minetest'
2018-04-23 23:02:44: ERROR[Main]: stack traceback:
2018-04-23 23:02:44: ERROR[Main]: 	[C]: in function 'dofile'
2018-04-23 23:02:44: ERROR[Main]: 	/home/user/.minetest/mods/medicine/init.lua:6: in main chunk
Here is my code:

Code: Select all

function minetest.register_poisoning_effect(player, pos, effect_time) -- line:1
    player:set_physics_override({
        speed = 0.4,
        jump = 0.4})
    
    minetest.hud_replace_builtin({
        hud_elem_type = "statbar",
        position = {x = 0.5, y = 1},
        text = "poisonous_heart.png",
        number = core.PLAYER_MAX_HP_DEFAULT,
        direction = 0,
        size = {x = 24, y = 24},
        offset = {x = (-10*24) - 25, y = -(48 + 24 + 16)},
    }

    minetest.add_particlespawner(amount = effect_time / 0.5,
        time = effect_time,
        min_pos = {x = pos.x + 0.5, y = pos.y, z = pos.z + 0.5},
        max_pos = min_pos,
        min_vel = 0.5,
        max_vel = 0.5,
        min_acc = 0,
        max_acc = 0,
        minexptime = effect_time,
        maxexptime = effect_time,
        minsize = 0.4,
        maxsize = 0.4,
        colissiondetection = true,
        vertical = true,
        texture = "poisonous_effect.png"
        
    })
        
    minetest.add_particlespawner(amount = effect_time / 0.5,
        time = effect_time,
        min_pos = {x = pos.x - 0.5, y = pos.y, z = pos.z + 0.5},
        max_pos = min_pos,
        min_vel = 0.5,
        max_vel = 0.5,
        min_acc = 0,
        max_acc = 0,
        minexptime = effect_time,
        maxexptime = effect_time,
        minsize = 0.4,
        maxsize = 0.4,
        colissiondetection = true,
        vertical = true,
        texture = "poisonous_effect.png"
        
    })
    
    minetest.add_particlespawner(amount = effect_time / 0.5,
        time = effect_time,
        min_pos = {x = pos.x + 0.5, y = pos.y, z = pos.z - 0.5},
        max_pos = min_pos,
        min_vel = 0.5,
        max_vel = 0.5,
        min_acc = 0,
        max_acc = 0,
        minexptime = effect_time,
        maxexptime = effect_time,
        minsize = 0.4,
        maxsize = 0.4,
        colissiondetection = true,
        vertical = true,
        texture = "poisonous_effect.png"
        
    })
    
    minetest.add_particlespawner(amount = effect_time / 0.5,
        time = effect_time,
        min_pos = {x = pos.x - 0.5, y = pos.y, z = pos.z - 0.5},
        max_pos = min_pos,
        min_vel = 0.5,
        max_vel = 0.5,
        min_acc = 0,
        max_acc = 0,
        minexptime = effect_time,
        maxexptime = effect_time,
        minsize = 0.4,
        maxsize = 0.4,
        colissiondetection = true,
        vertical = true,
        texture = "poisonous_effect.png"
        
    })
    
    for i = 1, effect_time do
        minetest.after(1, function (i, pos)
            if i // 2 == 0 then
                for h = 1, 3 do
                    if h == 1 then
                         minetest.after(0.1, minetest.add_particle({pos1 = {x = pos.x, y = pos.y, z = pos.z - 0.3},
                             velocity = {x = pos1.x, y = pos1.y + 0.4, z = pos1.z},
                             acceleration = nil,
                             expirationtime = 0.2,
                             size = 0.9,
                             collisiondetection = true,
                             collision_removal = true,
                             vertical = true,
                             glow = 0,
                             texture = "vomiting_1.png"
                             
                         })
                         
                    elseif h == 2 then
                        minetest.after(0.1, minetest.add_particle({pos1 = {x = pos.x, y = pos.y, z = pos.z - 0.3},
                            velocity = {x = pos1.x, y = pos1.y + 0.4, z = pos1.z},
                            acceleration = nil,
                            expirationtime = 0.2,
                            size = 0.9,
                            collisiondetection = true,
                            collision_removal = true,
                            vertical = true,
                            glow = 0,
                            texture = "vomiting_2.png"
                            
                        })
                        
                    elseif h == 3 then
                        minetest.after(0.1, minetest.add_particle({pos1 = {x = pos.x, y = pos.y, z = pos.z - 0.3},
                            velocity = {x = pos1.x, y = pos1.y + 0.4, z = pos1.z},
                            acceleration = nil,
                            expirationtime = 0.2,
                            size = 0.9,
                            collisiondetection = true,
                            collision_removal = true,
                            vertical = true,
                            glow = 0,
                            texture = "vomiting_3.png"
                            
                        })
                                                                   
                    end
                end
            end
        end
    end

    player:set_physics_override({
        speed = 1.0,
        jump = 1.0})
        
    minetest.hud_replace_builtin({
        hud_elem_type = "statbar",
        position = {x = 0.5, y = 1},
        text = "heart.png",
        number = core.PLAYER_MAX_HP_DEFAULT,
        direction = 0,
        size = {x = 24, y = 24},
        offset = {x = (-10*24) - 25, y = -(48 + 24 + 16)},
    })

end
    
It says there is needed symbol "=" near "minetest" on line:1. What for? This is definition of function, not giving a value to a varyable after all.

Also, if i have any other mistakes in this code?

And here you can download my file with the code:
function.zip
(1015 Bytes) Downloaded 15 times

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: An error with my function`s registration

by sofar » Post

You should not modify `minetest` by adding functions to it. This is an incompatible way to extend your mod functionality, and not OK.

Instead, make a new module namespace:

poison = {}

poison.register_effect = function(player, pos, time)
end

User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: An error with my function`s registration

by Andrey01 » Post

Thanks :)

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests