Jump to content

JSON problem


Wei

Recommended Posts

Posted
local storWeapon = fromJSON(getElementData(housePickup[houseID], "IGChousing.storedweapons")) 
if (type(storWeapon) == "table") then 
        local tableWeapon = storWeapon 
        if tableWeapon[getSlotFromWeapon(weapon)] then 
                tableWeapon[getSlotFromWeapon(weapon)] = weapon..","..tableWeapon[getSlotFromWeapon(weapon)]+ammo 
                setElementData(housePickup[houseID], "IGChousing.storedweapons", toJSON(tableWeapon)) 
                outputChatBox("In") 
        else 
                table.insert(tableWeapon, getSlotFromWeapon(weapon), weapon..","..ammo) 
                setElementData(housePickup[houseID], "IGChousing.storedweapons", toJSON(tableWeapon)) 
                outputChatBox("NotIn") 
        end 

Chatbox allways outputs NotIn.

No debug!

Diet with russian vodka, lose 3 days in one week !

Posted

And is the weapon in the table...?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You are checking the slot, do you know that?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
local storWeapon = fromJSON ( getElementData ( housePickup [ houseID ], "IGChousing.storedweapons" ) ) 
if ( type ( storWeapon ) == "table" ) then 
    local tableWeapon = storWeapon 
    if tableWeapon [ getSlotFromWeapon ( weapon ) ) ] then 
        tableWeapon [ getSlotFromWeapon ( weapon ) ] = weapon ..",".. tableWeapon [ getSlotFromWeapon ( weapon ) ] + ammo 
        setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) 
        outputChatBox ( "In" ) 
    else 
        tableWeapon [ getSlotFromWeapon ( weapon ) ] = weapon ..",".. ammo 
        setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) 
        outputChatBox ( "NotIn" ) 
    end 

This won't work btw:

 weapon ..",".. tableWeapon [ getSlotFromWeapon ( weapon ) ] + ammo 

You are trying to increase a string...

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Mind posting the "storWeapon" result?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Got it, you must convert your number to a string.

local storWeapon = fromJSON ( getElementData ( housePickup [ houseID ], "IGChousing.storedweapons" ) ) 
if ( type ( storWeapon ) == "table" ) then 
    local tableWeapon = storWeapon 
    local slot = tostring ( getSlotFromWeapon ( weapon ) ) 
    if tableWeapon [ slot ] then 
        tableWeapon [ slot ] = weapon ..",".. tableWeapon [ slot ] + ammo 
        setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) 
        outputChatBox ( "In" ) 
    else 
        tableWeapon [ slot ] = weapon ..",".. ammo 
        setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) 
        outputChatBox ( "NotIn" ) 
    end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...