[Mod] Xray [xray] - need some help

User avatar
InfinityProject
Member
Posts: 1009
Joined: Sat Mar 17, 2012 00:52
Location: World of Infinity, US

by InfinityProject » Post

Can someone help?
I keep getting "unexpected symbol near ==" at the xray(on) == nil

Code: Select all

if 
 XRAY_MODE == off
then 
 xray(on) == nil
end
if
 XRAY_MODE == on
then 
 xray(off) == nil
end

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

Use two == signs for an if, but use only one = sign for an assignment. In otherwords, it should be:

Code: Select all

if 
 XRAY_MODE == off
then 
 xray(on) = nil
(similarly for the xray(off) part as well)
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Post

InfinityProject wrote:Can someone help?
I keep getting "unexpected symbol near ==" at the xray(on) == nil

Code: Select all

if 
 XRAY_MODE == off
then 
 xray(on) == nil
end
if
 XRAY_MODE == on
then 
 xray(off) == nil
end

xray() is a function, you cant assign a variable to it

User avatar
Calinou
Moderator
Posts: 3169
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

by Calinou » Post

Some suggestion: hide some more common blocks: dirt, grass, leaves (but not trees), sand (and desert sand/stone) and gravel (set them to an invisible node different than invisible stone, and it should revert just fine, make the invisible gravel fall). :)

Also, why is the ABM's chance set to 4?

Disabling xray doesn't turn stone back to normal for me.

User avatar
InfinityProject
Member
Posts: 1009
Joined: Sat Mar 17, 2012 00:52
Location: World of Infinity, US

by InfinityProject » Post

Calinou wrote:Some suggestion: hide some more common blocks: dirt, grass, leaves (but not trees), sand (and desert sand/stone) and gravel (set them to an invisible node different than invisible stone, and it should revert just fine, make the invisible gravel fall). :)
I actually have gravel done and yes it does fall.

As for the abm I just chose a random number.

And yes, /xray off isn't working. For some reason the 2 commands counteract each other so so stone goes back and forth from invisible to visible. I need to find a way to turn a function off when the other one is on but I don't know how to do that.
Could you help?
My code:

Code: Select all

local function xray(mode)
XRAY_MODE = mode
end 


minetest.register_chatcommand("xray", {
    params = "<mode>",
    description = "Make stone invisible.",
    privs = {xray=true},    
    func = function(name, param)
        if param == 'on' then xray(on) 
          minetest.chat_send_player(name, "Xray turned on.") 
        elseif param == 'off' then xray(off) 
          minetest.chat_send_player(name, "Xray turned off.")
        else
          minetest.chat_send_player(name, "Please enter 'on' or 'off'.")
        end
    end,
})

minetest.register_abm({
        nodenames = {"default:stone", "xray:stone", "default:gravel", "xray:gravel"},
        interval = 0,
        chance = 1,    
        
        action = function(pos, node, active_object_count, active_object_count_wider)
          if XRAY_MODE == on and XRAY_ON ~= nil then
              if node.name == "default:stone" then
                  minetest.env:add_node(pos,{name="xray:stone"})
              elseif node.name == "default:gravel" then
                  minetest.env:add_node(pos,{name="xray:gravel"})
          elseif XRAY_MODE == off and XRAY_OFF ~= nil then
              if node.name == "xray:stone" then
                  minetest.env:add_node(pos,{name="default:stone"})
              elseif node.name == "xray:gravel" then
                  minetest.env:add_node(pos,{name="default:gravel"})
                end
            end
        end
    end
})
Last edited by InfinityProject on Mon Oct 08, 2012 22:31, edited 1 time in total.

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Post

does this work:
https://gist.github.com/3855913

I just removed "and XRAY_OFF ~= nil" and "and XRAY_ON ~= nil". They were undefined variables, and not used. I also changed on and off to strings (by putting quotes around them). Otherwise they will be interpreted as variables containing nil.

User avatar
InfinityProject
Member
Posts: 1009
Joined: Sat Mar 17, 2012 00:52
Location: World of Infinity, US

by InfinityProject » Post

The reason why the ~= nil was in there was because I was trying this:

Code: Select all

if 
 XRAY_MODE == off
then 
 XRAY_ON = nil and
 XRAY_OFF ~= nil
elseif
 XRAY_MODE == on
then 
 XRAY_OFF = nil and
 XRAY_ON ~= nil
end


local function xray_on(func)
 XRAY_ON = func
end

local function xray_off(func)
 XRAY_OFF = func
end

User avatar
InfinityProject
Member
Posts: 1009
Joined: Sat Mar 17, 2012 00:52
Location: World of Infinity, US

by InfinityProject » Post

Also that doesn't work either Cornernote. /xray off doesn't work at all with that.

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Post

I removed "if XRAY_MODE == 'off' then" from the elseif, and just made it an else.

If XRAY_MODE is not "on", then it has to run the off stuff now.

same gist link
Last edited by cornernote on Tue Oct 09, 2012 01:52, edited 1 time in total.

User avatar
InfinityProject
Member
Posts: 1009
Joined: Sat Mar 17, 2012 00:52
Location: World of Infinity, US

by InfinityProject » Post

cornernote wrote:I removed "if XRAY_MODE == 'off' then" from the elseif, and just made it an else.

If XRAY_MODE is not "on", then it has to run the off stuff now.

same gist link
That isn't working either. You need xray(off) defined in the abm.

I know what to do to fix this, but not how to do it.
I need to find a way to make xray(off) nil while xray(on) is activated and vice versa.

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Post

can you make a youtube video of the issue? i'm having trouble understanding what isnt working.

User avatar
InfinityProject
Member
Posts: 1009
Joined: Sat Mar 17, 2012 00:52
Location: World of Infinity, US

by InfinityProject » Post

Try it yourself (don't have any recording software)
https://dl.dropbox.com/u/82668184/xray%20test.zip

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Post

This works:
https://gist.github.com/3869515

There was a few issues. The 1st revision is yours, the next is a working version, and the third I tidied up all the tabs and spacing in the file.

Ok, the issues:

1)

Code: Select all

if param == 'on' then xray(on)
This will not work as expected. You are passing a variable (on) which is a NIL value (because you never set it to anything). What you want to do is pass the string "on". Like this:

Code: Select all

if param == 'on' then xray("on")

2)
I have no idea what all that XRAY_ON and XRAY_OFF was for. You don't need it. It's either on or off. Its not ON=1 and OFF=0 or ON=0 and OFF=1. Kepp it simple like this....
XRAY_MODE = "on" or "off".


3)
In your ABM it seemed you had an END that was out of place. It was really hard to see because your indents and new lines a little messy. I'll try to explain:

Code: Select all

        action = function(pos, node, active_object_count, active_object_count_wider)
        
          if XRAY_MODE == on and XRAY_OFF == nil then        <-- OPEN IF1
              if node.name == "default:stone" then               <-- OPEN IF2
                  minetest.env:add_node(pos,{name="xray:stone"})
              elseif node.name == "default:gravel" then            <-- ELSE IF2
                  minetest.env:add_node(pos,{name="xray:gravel"})
                                                                                              <-- I think you need to END here
          elseif XRAY_MODE == off and XRAY_ON == nil then    <-- ELSE IF2 -- i think you need an END before this
              if node.name == "xray:stone" then                       
                  minetest.env:add_node(pos,{name="default:stone"})
              elseif node.name == "xray:gravel" then
                  minetest.env:add_node(pos,{name="default:gravel"})
                end
            end                                                                              <-- i moved this END upto the place it should be
        end
    end
Last edited by cornernote on Thu Oct 11, 2012 01:15, edited 1 time in total.

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Post

Here is the ABM in your code with the indents cleaned up. This should help you to see the issue:

Code: Select all

minetest.register_abm({
    nodenames = {"default:stone", "xray:stone", "default:gravel", "xray:gravel"},
    interval = 0,
    chance = 1,    
    action = function(pos, node, active_object_count, active_object_count_wider)
        if XRAY_MODE == on and XRAY_OFF == nil then
            if node.name == "default:stone" then
                minetest.env:add_node(pos,{name="xray:stone"})
            elseif node.name == "default:gravel" then
                minetest.env:add_node(pos,{name="xray:gravel"})
            elseif XRAY_MODE == off and XRAY_ON == nil then
                if node.name == "xray:stone" then
                    minetest.env:add_node(pos,{name="default:stone"})
                elseif node.name == "xray:gravel" then
                    minetest.env:add_node(pos,{name="default:gravel"})
                end
            end
        end
    end
})

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Post

was just thinking about the reason for XRAY_ON and XRAY_OFF ...

Do you want a 3rd state where its neither on, nor off?

If so, set xray("inactive"), and then add a new condition to the ABM so that if its XRAY_MODE=="inactive" it does nothing.

madarexxx
Member
Posts: 144
Joined: Sat Aug 04, 2012 06:49

by madarexxx » Post

Need help. I turned xray on, look and tried to switch it off. Stone is still invisible, and my mine is unwalkable. Can i switch it off manually? For example with world edit (i don't know how to replace all nodes in some radius of selected point :( )
Sorry for my bad English, please help me learn it - correct my worst mistakes :)

User avatar
InfinityProject
Member
Posts: 1009
Joined: Sat Mar 17, 2012 00:52
Location: World of Infinity, US

by InfinityProject » Post

The mod was never finished. /off had never really worked. I think I found a way to finish it though.

madarexxx
Member
Posts: 144
Joined: Sat Aug 04, 2012 06:49

by madarexxx » Post

i've made it working. Sorry for no comments, but i'm tired, and want to sleep. May be i'll update it with comments tomorrow.
There are some changes:
1) It depends on worldedit now
2) /xray off and /xray on are affecting only 100*100*100 area
3) I've added new command - /xray globally_off, but IT IS FOR EXTREME TIMES! IT AFFECTS 1024*1024*1024 AREA!!!! IT IS F###ING SLOW!

https://www.dropbox.com/s/eor65i9t4t5w8g2/xray.tar.gz

P.S. Please test and comment!
Sorry for my bad English, please help me learn it - correct my worst mistakes :)

dheyviddacruzserafim
Member
Posts: 15
Joined: Fri Oct 20, 2017 20:43
IRC: deive
In-game: mesewars

Re: [Mod] Xray [xray] - need some help

by dheyviddacruzserafim » Post

could you link?

ranubix
New member
Posts: 1
Joined: Sun Dec 23, 2018 12:07
GitHub: shasait

Re: [Mod] Xray [xray] - need some help

by ranubix » Post

Hi all,

I implemented something comparable some days ago:
https://github.com/shasait/minetest-mod-xray

The block replacement supports multiple types of nodes - I started with: default:stone and default:stonebrick.
I took the original textures and applied some alpha to them, additionally I use the glasslike renderer so adjacent faces are not rendered, so you can still mine around with xray enabled.

The restoration works reliable and the algo is also suitable for multiplayer.

Happy mining

User avatar
ulla
Member
Posts: 142
Joined: Wed Feb 04, 2015 09:22
GitHub: IIIullaIII
IRC: ulla
In-game: ulla

Re: [Mod] Xray [xray] - need some help

by ulla » Post

dropbox no work, page 404 the link is broken
X4cna2d4UqsiawIzUumDgPoYNx3JLGII

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests