Bigjango13 / MCPI-Addons

Addons to the MCPI api.
17 stars 5 forks source link

custom attribute can't be found #5

Closed syang closed 1 year ago

syang commented 1 year ago

Here is my little script after I pip install the package

# this is the file of mod2.py

from mcpi_addons.minecraft import Minecraft
mc = Minecraft.create()

mc.postToChat("Hello, I am Gavin!")

pos = mc.player.getPos()
mc.postToChat(pos)
mc.custom.log.info("I am here")

And then I run the script $ python mod2.py, and I got the following error message,

Traceback (most recent call last):
  File "mod2.py", line 8, in <module>
    mc.custom.log.info("I am here")
AttributeError: 'Minecraft' object has no attribute 'custom'

Is it because I have not done anything about compiling section (did not run ./build.sh ....)

Bigjango13 commented 1 year ago

The custom attribute doesn't exist, instead look at what's next to it. For example:

  • custom.log.info (mc.log.info(msg)) Logs a message.

You would use mc.log.info("your message here").

syang commented 1 year ago

You would use mc.log.info("your message here").

I changed mod2.py into the following script.

from mcpi_addons.minecraft import Minecraft
mc = Minecraft.create()

mc.postToChat("Hello, I am Gavin!")

pos = mc.player.getPos()
mc.postToChat(pos)
mc.log.info("I am here")

Running python mod2.py gives the following error

Traceback (most recent call last):
  File "mod2.py", line 8, in <module>
    mc.log.info("I am here")
AttributeError: 'Minecraft' object has no attribute 'log'

I did not run the ./build.sh step in your Readme file, so I guess it may be the reason?

Bigjango13 commented 1 year ago

It seems I called it logging instead of log, should be fixed now.