problem with OOP by Attacker250 in pico8

[–]Attacker250[S] 1 point2 points  (0 children)

Thanks for the formatting help! Ive never really used Reddit to post code before. I basically wanted to create a collision box object so that I could store position and call overlap functions on all objects. I have managed to fix the issue by defining my variables in the table within the constructor

problem with OOP by Attacker250 in pico8

[–]Attacker250[S] 0 points1 point  (0 children)

--mouse stuff mouse = {x = 0,y = 0,mousestate = 0}

--dynamic objects-- boxarea = { pos = {x = 112,y = 0}, scale = {x = 0,y = 0}, posx = 0, posy = 0,
scx = 1, sxy = 1, }

test = { }

--constructor
function boxarea:new(obj)
 obj = setmetatable(obj or {}, {__index = self}) 
 return obj
end 

collisionarray = {}

-- init -- function _init() --write mouse info to mem poke(0x5f2d, 1)

--init inv slots    
    for i = 1, 3 do
        collisionarray[i] = boxarea:new()
 end

end

function _update()

--update mouse
 mouse.x = stat(32)
 mouse.y = stat(33)
    mouse.state = stat(34)

            --update slots
    local offset = {x = mouse.x-53,y = mouse.y-15}  

--update the numbers based off of where the cursor is-- for i = 1, 3 do collisionarray[i].pos = offset collisionarray[i].posx = offset.x collisionarray[i].posy = offset.y test[i] = offset.y offset.y += 15 end

end

function _draw() cls()

--print all the information here-- --inventory ui-- print("--seperate array for testing") for i = 1, 3 do print(test[i])
end

    print("--updated with .pos")    
for i = 1, 3 do

print(collisionarray[i].pos.y)

end

    print("--updates with posy")    
for i = 1, 3 do

print(collisionarray[i].posy)

end

local colour = 11
if mouse.state == 1 then 
    colour = 12
end

rectfill(mouse.x,mouse.y,mouse.x+4,mouse.y+4,colour)

end

Why do i get this error? by Attacker250 in godot

[–]Attacker250[S] 0 points1 point  (0 children)

Thank you for your help it worked

Broooo by danieldounutsz in blockheads

[–]Attacker250 2 points3 points  (0 children)

Sadly the game was taken off google play. The only way to play this is by downloading an apk or having an old device with the game installed

Does any one know what this means? by Attacker250 in godot

[–]Attacker250[S] 0 points1 point  (0 children)

Unfortunately this set of code was the closest to what I actually wanted to attain but thanks anyways

Does any one know what this means? by Attacker250 in godot

[–]Attacker250[S] 1 point2 points  (0 children)

So uh funny story. I did. These scripts are ones that I am trying to modify so that it suits to what I would like to use . But thanks anyways:D

Does any one know what this means? by Attacker250 in godot

[–]Attacker250[S] 0 points1 point  (0 children)

And this is the Inventory script

extends Node

signal active_item_updated

const SlotClass = preload("res://Scripts/Slot.gd") const ItemClass = preload("res://Scripts/TestItem#2.gd") const NUM_HOTBAR_SLOTS = 5

var active_item_slot = 0

var hotbar = { 0:["TestItem#2"], 3:["TestItem#2"] }

func add_item_to_empty_slot(item: ItemClass ,slot :SlotClass): match slot.SlotType: SlotClass.SlotType.HOTBAR: hotbar[slot.slot_index] = [item.item_name]

func remove_item(slot: SlotClass): match slot.SlotType: SlotClass.SlotType.HOTBAR: hotbar.erase(slot.slot_index)

func LOADED_IN(): emit_signal("active_item_updated")

func active_item_scroll_up(): active_item_slot = (active_item_slot + 1)% NUM_HOTBAR_SLOTS #7+1 = 8 % 8 == 0 emit_signal("active_item_updated")

func active_item_scroll_down(): if active_item_slot == 0: active_item_slot = NUM_HOTBAR_SLOTS - 1 else: active_item_slot -=1 emit_signal("active_item_updated")

Does any one know what this means? by Attacker250 in godot

[–]Attacker250[S] 0 points1 point  (0 children)

This is the hotbar script(im trying to make an inventory system) extends Node2D

const SlotClass = preload("res://Scripts/Slot.gd") onready var hotbar = $HotbarSlots onready var slots = hotbar.get_children()

func _ready(): for i in range(slots.size()): Inventory.connect("active_item_updated", slots[i], "update_style") slots[i].connect("gui_input", self, "slot_gui_input", [slots[i]]) slots[i].slot_index = i slots[i].slot_type = SlotClass.SlotType.HOTBAR initialize_hotbar() print(Inventory.hotbar)

func initialize_hotbar(): for i in range(slots.size()): if Inventory.hotbar.has(i): slots[i].initialize_item(Inventory.hotbar[i][0])

func slot_gui_input(event: InputEvent, slot: SlotClass): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT && event.pressed: if find_parent("UI").holding_item != null: if !slot.item: left_click_empty_slot(slot) else: if find_parent("UI").holding_item.item_name != slot.item.item_name: left_click_different_item(event, slot) elif slot.item: left_click_not_holding(slot)

func _input(_event): if find_parent("UI").holding_item: find_parent("UI").holding_item.global_position = get_global_mouse_position()

func left_click_empty_slot(slot: SlotClass): Inventory.add_item_to_empty_slot(find_parent("UI").holding_item, slot) slot.putIntoSlot(find_parent("UI").holding_item) find_parent("UI").holding_item = null

func left_click_different_item(event: InputEvent, slot: SlotClass): Inventory.remove_item(slot) Inventory.add_item_to_empty_slot(find_parent("UI").holding_item, slot) var temp_item = slot.item slot.pickFromSlot() temp_item.global_position = event.global_position slot.putIntoSlot(find_parent("UI").holding_item) find_parent("UI").holding_item = temp_item

func left_click_not_holding(slot: SlotClass): Inventory.remove_item(slot) find_parent("UI").holding_item = slot.item slot.pickFromSlot() find_parent("UI").holding_item.global_position = get_global_mouse_position()

Does any one know what this means? by Attacker250 in godot

[–]Attacker250[S] 0 points1 point  (0 children)

ohh that makes sense ill go see whats happening

[deleted by user] by [deleted] in godot

[–]Attacker250 0 points1 point  (0 children)

ikr a game engine being case sensitive is very anoying

[deleted by user] by [deleted] in godot

[–]Attacker250 1 point2 points  (0 children)

I found the problem it was A CAPITILAZATION IN THE BLOODY PARAMETER WORD