WatWat Posted May 30, 2016 Share Posted May 30, 2016 [143] => Array ( [name] => Earbuds [quality] => 6 [tradable] => 1 [craftable] => 1 [priceindex] => 0 [currency] => keys [value] => 392 [ID] => 3590608904 ) This output is my problem. These earbuds are craftable and therefore should be worth only 2.7 keys or something like that. Instead, my code bugs out and says that the value is that of uncraftable earbuds. Would anybody mind looking over the relevant code snippet to help me out with this? I'm basically looping through both the GetPlayerItems API as well as the priceing API by bp.tf and go down the right "path" to end up with the right price and all. If anybody knows a better way to go about this I'd really appreciate that as well! And here's the code snippet: $st_items = $raw_steam_api['result']['items']; $bp_items = $bp_prices['Items']; //loop through steam items foreach($st_items as $st_item){ $defindex = $st_item['defindex']; //loop through bptf items foreach ($bp_items as $bp_item_name => $bp_item) { //check whether the item defindex is in bptf if(in_array($defindex, $bp_item['defindex'])) { // Loop through the qualities in the price foreach ($bp_item['prices'] as $bp_quality => $bp_quality_price) { if($st_item['quality'] == $bp_quality){ // Loop through tradable/untradable values foreach ($bp_quality_price as $bp_tradable => $bp_tradable_price) { // if tradable if(!isset($st_item['flag_cannot_trade']) && $bp_tradable == 'Tradable'){ $tradable = true; // Loop through craftable/uncraftable values foreach ($bp_tradable_price as $bp_craftable => $bp_craftable_price) { //if craftable if(!isset($st_item['flag_cannot_craft']) && $bp_craftable == 'Craftable'){ $craftable = true; } //if non-craftable elseif( isset($st_item['flag_cannot_craft']) && $bp_craftable == 'Non-Craftable') { $craftable = false; } foreach ($bp_craftable_price as $bp_priceindex => $bp_item_price) { //if "regular" item if($bp_priceindex == 0 && isset($craftable)){ $output[$defindex]['name'] = $bp_item_name; $output[$defindex]['quality'] = $st_item['quality']; $output[$defindex]['tradable'] = $tradable; $output[$defindex]['craftable'] = $craftable; $output[$defindex]['priceindex'] = $bp_priceindex; $output[$defindex]['currency'] = $bp_item_price['currency']; $output[$defindex]['value'] = $bp_item_price['value']; $output[$defindex]['ID'] = $st_item['id']; //don't mind those silly brackets. They're all there and orderly in my original piece of code. Copy pasting is hard... } } } } } } } } } Link to comment Share on other sites More sharing options...
StoneWolf Posted May 30, 2016 Share Posted May 30, 2016 Change isset($craftable) to isset($craftable) && $craftable, I guess? You're only checking whether $craftable is set, but not if it's actually true or false. Therefore the last price in the price array will always be the one stored in the end of your loop. Link to comment Share on other sites More sharing options...
WatWat Posted May 30, 2016 Author Share Posted May 30, 2016 isset($craftable) && $craftable ? You're only checking whether $craftable is set, but not if it's actually true or false. Therefore the last price in the price array will always be the one stored in the end of your loop. Your suggestion doesn't quite work because uncraftable items also have a price. I appear to have fixed that by setting $craftfable to null right after entering its respective loop. foreach ($bp_tradable_price as $bp_craftable => $bp_craftable_price) { $craftable = null; Silly me tried to fix it by setting it to null in the very first foreach loop. Consider this fixed! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.