Are all variables global and not instanced?

This might sound like a stupid question, but i’d assumed variables were instanced (as in, per item) on items.

On player I call emit "notinroom" as part of the draw event. // this works fine.

This calls a function in an item (or rather, on all items of that type) that resets a variable to 0, so the function doesn’t recur.

on notinroom do
	
	if roomname=="start" then  //custom what room we in check
		if readytoharvest==1 then    
				readytoharvest = 0                 //reset the variable
	      	                swap "PlantedCollectable"    //do the swap
		                                  end
                              end

end

But once it finds that variable for “readytoharvest” it seems to be going “okay let’s just swap the 1st tile we find and call it a day”.

My question is then, are variables on items global and not local/instanced?
In which case, can I flag a variable as instanced / unique / per item?
Actually loosing my mind over this lol.

Documentation says global and indeed they are global.

To keep variable namespace clean I use an underscore before any local variable. For example _foo

Then I make double sure to initialize the “local” variable before use. To be clear that does not make the variable a true local or instanced variable. You need to work with the limited constructs Pulp has and that means moving away from object orientism. Assembly would be a better reference point.

1 Like

@0x143 Yeah that’s what i’m struggling with jumping from OOP.

For context it’s a farming game so you plant up a field with 30-50 “items”, with a “growing” timer and a “Is it ready to harvest” check.

Can’t figure a way to do that check per item tile without using instanced variables or just having 30 duplicate items with a variable for each. Open to any suggestions bud!

Haha, you figured it out though. Pulp isn’t a tool for complex games so emulating complex games requires compromising. Both in making your code dirty, and also maybe letting the player plant 5 max not 30.

3 Likes

Have the sprite contain if it's ready to harvest. So the time swaps through the different growing sprites, then each sprite as a state. The last grown veggie can be harvested.

Maybe?