Page 1 of 1

Question for a "nil value"[solved]

PostPosted: Thu Apr 14, 2016 14:57
by azekill_DIABLO
i'm actually doing a mod:

on_rightclick = function(self, clicker)

-- talk to the player
minetest.chat_send('BLABLABLAblaBLObla');

-- by right-clicking owner can switch Mob between follow and stand

if self.owner and self.owner == clicker:get_player_name() then


if self.order == "follow" then
self.order = "stand"
else
self.order = "follow"
end
end
end,})

i have problems with the underlined part?

In other words how to make talk a NPC on right-click?

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 15:08
by maikerumine
azekill_DIABLO wrote:i'm actually doing a mod:

on_rightclick = function(self, clicker)

-- talk to the player
minetest.chat_send('BLABLABLAblaBLObla');

-- by right-clicking owner can switch Mob between follow and stand

if self.owner and self.owner == clicker:get_player_name() then


if self.order == "follow" then
self.order = "stand"
else
self.order = "follow"
end
end
end,})

i have problems with the underlined part?


Chat part:
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
local_chat(clicker:getpos(),"Sam: Let's go kick some Mob butt!",3)


Add this to api:
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
         --Reese chat
         local_chat = function(pos,text,radius)
            if radius == nil then
               radius = 25
            end
            if pos ~= nil then
               local oir = minetest.get_objects_inside_radius(pos, radius)
               for _,p in pairs(oir) do
                  if p:is_player() then
                     minetest.chat_send_player(p:get_player_name(),text)
                  end
               end
            end
         end

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 15:15
by azekill_DIABLO
thak you for your fast awnser!!!


Edit: there is a problem, i got this error:
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
2016-04-14 17:20:39: ERROR[main]: ========== ERROR FROM LUA ===========
2016-04-14 17:20:39: ERROR[main]: Failed to load and run script from
2016-04-14 17:20:39: ERROR[main]: C:\Games\Minetest\bin\..\mods\smb\init.lua:
2016-04-14 17:20:39: ERROR[main]: C:\Games\Minetest\bin\..\mods\smb\init.lua:113: '=' expected near 'if'
2016-04-14 17:20:39: ERROR[main]: ======= END OF ERROR FROM LUA ========
2016-04-14 17:20:39: ERROR[main]: Server: Failed to load and run C:\Games\Minetest\bin\..\mods\smb\init.lua
2016-04-14 17:20:39: ERROR[main]: ModError: ModError: Failed to load and run C:\Games\Minetest\bin\..\mods\smb\init.lua
2016-04-14 17:20:39: ERROR[main]: Error from Lua:
2016-04-14 17:20:39: ERROR[main]: C:\Games\Minetest\bin\..\mods\smb\init.lua:113: '=' expected near 'if'

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 15:31
by maikerumine
I would need to see full init to figure that one out. maybe your follow code is missing something, or even a misplaced comma.

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 15:41
by azekill_DIABLO
Here is the full init.lua
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
print("Super Mario Bros mod is loading....")
print("A mod by azekill_DIABLO on an idea of MineYoshi")

mobs:register_mob("smb:toad",
{type = "npc",
passive = false,
damage = 1,
attack_type = "dogfight",
attacks_monsters = true,
pathfinding = true,
collisionbox = {-0.4, -0.4, -0.4, 0.4, 0.6, 0.4},
visual = "sprite",
textures = {
   {"toad.png"},},
blood_texture = "blood_smb.png",
makes_footstep_sound = true,
sounds = {
   random = "snap",},
view_range = 25,
walk_velocity = 3,
run_velocity = 3,
jump = true,
drops = {
   {name = "smb:toad",
   chance = 0, min = 1, max = 1},},
owner = "",
order = "follow",
water_damage = 0,
lava_damage = 5,
light_damage = 0,
fear_height = 1, 
 
on_rightclick = function(self, clicker)

   -- by right-clicking owner can switch TOAD between follow and stand
      if self.owner and self.owner == clicker:get_player_name() then

         if self.order == "follow" then
            self.order = "stand"
         else
            self.order = "follow"
         end
      end
   end,})

mobs:register_egg("smb:toad", "TOAD YOUR BEST FRIEND", "toad.png", 1)

mobs:register_mob("smb:bowser", {
type = "monster",
passive = false,
damage = 8,
attack_type = "dogshoot",
reach = 0.5,
shoot_interval = 1,
arrow = "smb:bowser_breath",
shoot_offset = 1,
hp_min = 65,
hp_max = 65,
armor = 100,
collisionbox = {-0.7, -0.8, -0.7, 0.7, 0.7, 0.7},
visual = "sprite",
textures = {
   {"bowser.png"},},
visual_size = {x=2, y=2},
blood_texture = "blood_smb.png",
makes_footstep_sound = true,
sounds = {
   random = "mobs_dungeonmaster",
   shoot_attack = "mobs_fireball",},
walk_velocity = 1,
run_velocity = 3,
jump = true,
view_range = 15,
drops = {
   {name = "default:diamondblock", chance = 0, min = 1, max = 1},},
water_damage = 1,
lava_damage = 1,
light_damage = 0,
fear_height = 3,})

mobs:register_arrow("smb:bowser_breath", {
   visual = "sprite",
   visual_size = {x = 1, y = 1},
   textures = {"bowser_breath.png"},
   velocity = 8,

   -- direct hit, no fire... only scream and horror
   hit_player = function(self, player)
      player:punch(self.object, 0.5, {
         full_punch_interval = 0.5,
         damage_groups = {fleshy = 8},
      }, nil)
   end,

   hit_mob = function(self, player)
      player:punch(self.object, 0.5, {
         full_punch_interval = 0.5,
         damage_groups = {fleshy = 8},
      }, nil)
   end,

   -- node hit, bursts into flame (not too much)
   hit_node = function(self, pos, node)
      mobs:explosion(pos, 1, 0.5, 0.5)
   end
})

mobs:register_egg("smb:bowser", "BOWSER YOUR WORST FOE", "bowser.png", 1)

--Reese chat
    local_chat = function(pos,text,radius)
  
if radius == nil then
        
radius = 25
      
end
  
if pos ~= nil then
   
local oir = minetest.get_objects_inside_radius(pos, radius)
   
for _,p in pairs(oir) do
        
if p:is_player() then
                  
minetest.chat_send_player(p:get_player_name(),text)
                
end
             
end
          
end
      
end


mobs:register_mob("smb:peach",
{type = "npc",
passive = true,
hp_min = 80,
hp_max = 80,
armor = 100,
collisionbox = {-0.3, -0.6, -0.3, 0.3, 0.3, 0.3},
visual = "sprite",
visual_size = {x=1.5, y=1.5},
textures = {
   {"peach.png"},},
blood_texture = "flower.png",
makes_footstep_sound = true,
sounds = {
   random = "snap",},
view_range = 25,
walk_velocity = 2,
run_velocity = 2,
jump = true,
drops = {
   {name = "smb:peach",
   chance = 0, min = 1, max = 1},},
water_damage = 0,
lava_damage = 0,
light_damage = 0,
fear_height = 10,

on_rightclick = function(self, clicker)
   
-- talk to the player   
   
   local_chat(clicker:getpos(),"Peach: Thank you for saving me!!!",3)
   
-- by right-clicking owner can switch PEACH between follow and stand
      if self.owner and self.owner == clicker:get_player_name() then
         if self.order == "follow" then
            self.order = "stand"   
         else
            self.order = "follow"
         end      
      end
   end,})

mobs:register_egg("smb:peach", "PEACH THE PRINCESS", "peach.png", 1)

mobs:register_mob("smb:goomba", {
type = "monster",
passive = false,
damage = 4,
attack_type = "dogfight",
reach = 1,
hp_min = 35,
hp_max = 35,
armor = 100,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "sprite",
textures = {
   {"goomba.png"},},
visual_size = {x=1.5, y=1.5},
blood_texture = "blood_smb.png",
makes_footstep_sound = true,
sounds = {
   random = "mobs_dungeonmaster",},
walk_velocity = 1,
run_velocity = 3,
jump = true,
view_range = 15,
drops = {
   {name = "default:diamond", chance = 0, min = 1, max = 1},},
water_damage = 2,
lava_damage = 10,
light_damage = 0,
fear_height = 3,})

mobs:register_egg("smb:goomba", "GOOMBA THE... GOOMBA", "goomba.png", 1)

print("The SMB mod is loaded. Have Fun!!(and get rekt by bowser)")

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 16:47
by maikerumine
agg, you need to put the "reese chat" part in the api, not the init/

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 16:50
by azekill_DIABLO
ah ok:)

EDIT:

now i have the same error for the api.lua!THE SAME!

:) lol

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 19:16
by TumeniNodes
you have :
--Reese chat
local_chat = function(pos,text,radius)
if radius == nil then
radius = 25
end
if pos ~= nil then <this line need to change out ~ with =

at least I THINK that may be what is throwing the error, I could be completely wrong. If I am then full apologies

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 20:03
by cheapie
thegreatone wrote:if pos ~= nil then <this line need to change out ~ with =

at least I THINK that may be what is throwing the error, I could be completely wrong. If I am then full apologies


There's nothing wrong with "~=". It's the opposite of "==".

Re: Question for a "nil value"

PostPosted: Thu Apr 14, 2016 20:15
by rubenwardy
You should indent your code properly, right now it's unreadable. At the top of the file, you should start with an indent of 0. Every time you open a function, if statement, for/while loop, or some other code block you should indent in once. Also indent in for def tables.

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
mob.register("name", {
    one = "two",
    three = "four",
    on_foo = function(player, pos)
        local pos2 = {x = pos.x, y = pos.y + 1, z = pos.z}
        minetest.chat_send_player(player:get_player_name(), "Hello!")
    end
})

function something(one, two, three)
    print(one .. " is " .. two .. " and " .. three)
end

Re: Question for a "nil value"

PostPosted: Fri Apr 15, 2016 10:33
by azekill_DIABLO
thegreatone wrote:you have :
--Reese chat
local_chat = function(pos,text,radius)
if radius == nil then
radius = 25
end
if pos ~= nil then <this line need to change out ~ with =

at least I THINK that may be what is throwing the error, I could be completely wrong. If I am then full apologies


i will try what you said :)


@cheapie : if u say it
@Rubenwardy : ok ok....

Re: Question for a "nil value"[solved]

PostPosted: Fri Apr 15, 2016 10:59
by azekill_DIABLO
that was super easy i solved it in 5 min without api.lua :)

just by adding this little function:

minetest.chat_send_player(clicker:get_player_name(), "MSG to the player")

Re: Question for a "nil value"

PostPosted: Fri Apr 15, 2016 12:05
by TumeniNodes
azekill_DIABLO wrote:
thegreatone wrote:you have :
--Reese chat
local_chat = function(pos,text,radius)
if radius == nil then
radius = 25
end
if pos ~= nil then <this line need to change out ~ with =

at least I THINK that may be what is throwing the error, I could be completely wrong. If I am then full apologies


i will try what you said :)




Unfortunately, I was mistaken. I probably should not have offered any advice as I am just learning Lua myself. I figured I would at least try to help because I know what it is like to keep getting an error and going nuts going back and forth over the code to see what is missing or misplaced, (usually has to do with a comma haha)
Anyway, glad to see you figured it out
Cheers

Re: Question for a "nil value"[solved]

PostPosted: Fri Apr 15, 2016 14:32
by azekill_DIABLO
:) thank @all for your help