Page 1 of 2

Can a ABM?

PostPosted: Thu Apr 19, 2012 16:48
by Jordach
ABM change a node to a random node, such as node:alpha_1 to node:alpha_5 and then node:alpha_3 ??

Making a TV is really hard.

PostPosted: Thu Apr 19, 2012 16:50
by sfan5
Yep

PostPosted: Thu Apr 19, 2012 16:50
by Jordach
Awesome? Care to share?

As in:

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_abm(
        {nodenames = {"default:test_1"},
        interval = 0,
        chance = 1,
        action = function(pos)
                minetest.env:add_node(pos, {name="default:test_.math.random(1,10)"})
        end,
})

PostPosted: Thu Apr 19, 2012 16:57
by mauvebic
look at my trafficlights

PostPosted: Thu Apr 19, 2012 16:58
by Jordach
I need something like math.random(1,10) to change the nodes around, kddkadenz's desert mod is helping.

PostPosted: Thu Apr 19, 2012 17:09
by mauvebic
what are you trying to do?

PostPosted: Thu Apr 19, 2012 17:13
by Jordach
Do something really clever.

PostPosted: Thu Apr 19, 2012 17:20
by Jordach
I just found the answer I hope.

PostPosted: Thu Apr 19, 2012 17:30
by Jordach
I needed to use this:

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 i = math.random(1,10)

if i = 1 then
    minetest.env:add_node(pos, {node:generic})


This under a ABM plus this:
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_abm(
        {nodenames = {"tv:screen_1", "tv:screen_2", "tv:screen_3", "tv:screen_4", "tv:screen_5", "tv:screen_6", "tv:screen_7", "tv:screen_8", "tv:screen_9", "tv:screen_10"},


Is how I almost got it to work. This has not BEEN TESTED, WILL GIVE A RELEASE ON GIT SOON.

PostPosted: Thu Apr 19, 2012 17:35
by mauvebic
you want a tv that flickers between channels?

PostPosted: Thu Apr 19, 2012 17:37
by Jordach
No no. But I am almost done. Just add textures.

PostPosted: Thu Apr 19, 2012 17:49
by Jordach
Problem:

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 i = math.random(1,10)

if i== 1 then
    minetest.env:add_node(pos, {node:generic})
    end
end


This makes an error, and function is (pos) what is my error.

PostPosted: Thu Apr 19, 2012 17:57
by mauvebic
you seem to have an extra 'end' statement

PostPosted: Thu Apr 19, 2012 17:59
by mauvebic
Jordach wrote:Problem:

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.env:add_node(pos, {node:generic})




try this instead:
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.env:add_node(pos,{type="node",name='node:generic'})

PostPosted: Thu Apr 19, 2012 18:06
by Jordach
Keeps on saying: function arguments expected near '}'

No code change.

PostPosted: Thu Apr 19, 2012 18:07
by mauvebic
if you know which line the errors happenning on post that portion of the code, else post the whole thing and ill take a look

looks more like a LUA syntax/typo thing than a modding API thing

PostPosted: Thu Apr 19, 2012 18:10
by Jordach
mauvebic wrote:if you know which line the errors happenning on post that portion of the code, else post the whole thing and ill take a look

looks more like a LUA syntax/typo thing than a modding API thing

Email sent.

PostPosted: Thu Apr 19, 2012 18:10
by mauvebic
in debug.txt it should tell you which line is causing the problem

PostPosted: Thu Apr 19, 2012 18:11
by Jordach
Mail sent.

PostPosted: Thu Apr 19, 2012 18:12
by mauvebic
line 130: you have a comma after end

PostPosted: Thu Apr 19, 2012 18:14
by Jordach
Changed that, nothing doing.

PostPosted: Thu Apr 19, 2012 18:15
by mauvebic
and in
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
{name=tv:screen_1}


should be

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
{name="tv:screen_1"}

PostPosted: Thu Apr 19, 2012 18:18
by Jordach
It works!

PostPosted: Thu Apr 19, 2012 18:24
by mauvebic
try this:
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
--Tv Mod, by Jordan Snelling 2012.
--Mauvebic, did I miss anything, or get anything wrong?

minetest.register_node("tv:screen_1", {
    description = "TV",
    tile_images = {"tv_screen_1.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_2", {
    description = "TV",
    tile_images = {"tv_screen_2.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_3", {
    description = "TV",
    tile_images = {"tv_screen_3.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_4", {
    description = "TV",
    tile_images = {"tv_screen_4.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_5", {
    description = "TV",
    tile_images = {"tv_screen_5.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_6", {
    description = "TV",
    tile_images = {"tv_screen_6.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_7", {
    description = "TV",
    tile_images = {"tv_screen_7.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_8", {
    description = "TV",
    tile_images = {"tv_screen_8.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_node("tv:screen_9", {
    description = "TV",
    tile_images = {"tv_screen_9.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})
minetest.register_node("tv:screen_10", {
    description = "TV",
    tile_images = {"tv_screen_10.png"},
    is_ground_content = true,
    groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
    drop = 'tv:screen_1',
})

minetest.register_abm({
        nodenames = { "startrek:viewscreen" },
        interval = 3,
        chance = 3,
       
        action = function(pos, node, active_object_count, active_object_count_wider)
            minetest.env:add_node({x=pos.x,y=pos.y,z=pos.z},{type="node",name="startrek:viewscreenoff"})
        end
})
minetest.register_abm(
    {nodenames = {"tv:screen_1", "tv:screen_2", "tv:screen_3", "tv:screen_4", "tv:screen_5", "tv:screen_6", "tv:screen_7", "tv:screen_8", "tv:screen_9", "tv:screen_10"},
    interval = 2000,
    chance = 200,
    action = function(pos)
        local i = math.random(1,10)
       
            if i== 1 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_1"})
       
            elseif i== 2 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_2"})

            elseif i== 3 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_3"})
       
            elseif i== 4 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_4"})
       
            elseif i== 5 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_5"})

            elseif i== 6 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_6"})
       
            elseif i== 7 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_7"})
       
            elseif i== 8 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_8"})
       
            elseif i== 9 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_9"})
       
            elseif i== 10 then
                minetest.env:add_node(pos,{type="node",name="tv:screen_10"})
            end
       
        end
})

PostPosted: Thu Apr 19, 2012 18:28
by Jordach
Just made the changes by hand, they work.

PostPosted: Thu Apr 19, 2012 18:31
by mauvebic
yeah you had a syntax error here:

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.env:add_node(pos,{type="node",name="tv:screen_5"))


shoulda been:

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.env:add_node(pos,{type="node",name="tv:screen_5"})

PostPosted: Thu Apr 19, 2012 18:32
by Jordach
Actually, you don't need the type="node", this seems to check whether the drawtype is, a cube, sign fence post and what not.

PostPosted: Thu Apr 19, 2012 18:37
by mauvebic
thats prolly right, half my mods have register crafts that use node "themod:thenode" and the other half use simply themod:thenode

PostPosted: Thu Apr 19, 2012 18:40
by Jordach
I set the interval and chance to 1, 1. They shuffled like dice!

PostPosted: Thu Apr 19, 2012 18:41
by mauvebic
allright but keep in mind, the more of your nodes are in the game, the more FPS intense the abms get.