Wei Posted August 1, 2013 Posted August 1, 2013 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!
Castillo Posted August 1, 2013 Posted August 1, 2013 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...
Castillo Posted August 1, 2013 Posted August 1, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now