ZeroBraneStudio does not display hashed values correctly

The code below can be tested. You will see that the table is not correct when viewed inside ZeroBraneStudio but prints out correctly.


local dbg = require("builtins.scripts.mobdebug")
    function init(self)
    	dbg.start()
    	local options = {
    		spawn_types = {
    			{animal_cat = 		2},			 
    			{animal_dog = 		2},
    			{animal_fish  = 	2},
    			{object_crate = 	1},
    			{object_dynamite = 	1},
    			{object_chainsaw = 	1}
    		}
    	}

    	local spawn_types = {}
    	
    	local type_mapping = {
    		animal_cat =     {class = hash("animal"), type = hash("cat")},
    		animal_dog =    {class = hash("animal"), type = hash("dog")},
    		animal_fish =   {class = hash("animal"), type = hash("fish")},
    		animal_giraffe =    {class = hash("animal"), type = hash("giraffe")},
    		object_crate =    {class = hash("object"), type = hash("crate")},
    		object_dynamite = {class = hash("object"), type = hash("dynamite")},
    		object_chainsaw = {class = hash("object"), type = hash("chainsaw")}
    	}	

    	local class
        local type
    	local spawn_type
    	for k, v in pairs(options.spawn_types) do
    		for class_type, ratio in pairs(v) do
        		class = type_mapping[class_type].class
        		type = type_mapping[class_type].type
        
        		spawn_type = {class = class, type = type, ratio = ratio}
    			spawn_types[k] = spawn_type
    		end
    	end

    	print("Level can spawn:")
    	pprint(spawn_types) --break here and look at spawn_types in ZeroBraneStudio	

    end

This looks like an error in ZeroBrane debugger actually. When I pprint() the table it looks OK.

1 Like

The table you create has only one element, containing the table:

{type = hash(“type_a”), speed =10, {type = hash(“type_a”), speed = 15}

So a second element does not exist and thus returns nil.

EDIT: see below.

1 Like

Sorry, something is not right in your code. There’s unbalanced {} so you should get an error. Did you copy the whole thing?

1 Like

I’ve changed the bug. It;s a ZeroBraneStudio bug not Defold.

1 Like