Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

trash engine

A small and trashy, quick and dirty game engine · By Niki

Global variable?

A topic by Dzhake created Nov 05, 2023 Views: 327 Replies: 12
Viewing posts 1 to 9
(1 edit) (+1)

Hi! First of all is obv "WoW this is really cool especially because i can take trashovania and add some heck to it..

I want to make trashovania mod which adds new game mode. It should modify some behavious. But, i need global variable for that! Cuz i need to store if this mode is enabled! (i can make literally another game, not just add gamemode, but idk, and global variables is still good idea :>) It it possible to make global variable somehow? I'm not sure if i can store my variable in player because title screen has no player :(

Edit: death uses "persist()". Maybe i can use it but idk how :) Also i decided to make separate game :> But global variables is still good idea..

(6 edits)

Also, how do i use "MoveRooms()"? Lol. Can you PLEAASEE Include "goToRoom()" In quickref.md? Cuz i used search and that function exists! I always wanted it! ...uh i'm using this engine two days... You really MUST add it cuz that's very confusing that you can only go next/previous room and reorder them >_<

edit uh 4th one?: Wait, moveRooms() is not moveRooms, it's change room to uhh currentRoomNumber+Difference (⊙ˍ⊙)

Looks like now best solution is to create object on main menu and make it persistent :)

So uhh i published my game just because i wanted to have at least one project on itch.io :> Actually, because it's kinda playable now :>

https://dzhake.itch.io/trashovania-dzhakes-mod

I can't fix a error :(

I created "gamemode" sprite with "isIronMode" public property. gamemode sets isIronMode to false (outside "onUpdate", so only on start ig). Then, in main menu i have created third callback "() => { gm.isIronMode = !gm.isIronMode; }," , and placed gamemode in main menu room. When i use "gm = findClosest(gamemode);" in menuMain sprite it says "can't read properties of undefined" :(

(4 edits)

(i somehow reached post charcters limit xD (it's 20k..)) I also tried to create gamemode in menuMain, but i "compile error in gamemode" in console.

All the code for gamemode is this, what could even error here??

public properties:

gamemode

isIronMode

code:

imgAlpha = 0;

persist(me,1);

gamemode = "normal";

isIronMode = false;

Even if i comment all lines it still errors >_<


(6 edits)

When i save game in trash engine it also changes in itch.io.... WHY AND HOW AND CAN I STOP THIS SOMEHOW??? Y'know, i don't think version control things like git were created for fun :>

EDIT: I commented "upgrade()" and everything is fine now lol. Can you please add option in editor "auto-upgrade exported game"?? If no then i can try myself hehe

edit2: i uploaded it to itch.io after commenting upgrade() and... it doesn't work??? lol?????????

edit3: oh, that was build issue. So when i just open .html in browser, even if "upgrade()" is uncommented, it launches version with which it was exported. But itch.io auto-updates it........ wtf...

edit4: I uploaded it my github page, and... it didn't update.. uh what.

edit5: probably just a github pages issue. Tho idk how else i can check.

Developer

Hey hey :) Ok I see you've been messing around a bunch ^-^ and it actually fills me with joy someone is using the engine to make something!

I will try to go through the things in order as I understand them:

Global variable: you can put the variable on the window like "window.something = 2;". But putting in on a persistent object is also not a bad idea.

I never realized goToRoom is not in the reference, I think I simply forgot. You use it like this: "goToRoom(room0)", room0 being the name of the room (trash engine creates a global variable for every room/sprite/etc pointing to an internal room id). For trashovania I do some funny hacking to make the rooms work, I think, something like window["room_"+x+"_"+y], to access those global variables.

On findClosest: Calling this function on creation might not work, since the instances are created in a certain order, so it might not exist yet. Also for findClosest you need to provide x,y coordinates, if you just want to find any object use find(gamemode).

On the versions issue: Not at all sure what's going on. But relevant information is that trash engine stores game data in your browser. So if you make changes to, for example, trashovania, using the remix functionality, those changes will stay until you clear the indexeddb storage in your browser or use the "delete data" button in the settings. This is tied to the domain (like itch.io) and the game id (which you can change in the settings), so there can be some problems where different games access the same save data. If you go to the settings in your mod and change the id to something else that might fix it, but just a guess. The browser save data system was quite complicated to implement, and I'm not confident that there aren't any bugs in it. Also not exactly sure what kind of "upgrade()" you are referring to, kind of blanking on this one.

I don't think there really is a good way to use trash engine with version control. There is the save/load system, or you just export the game regularly and keep those as backups. The project on github is really just for developing the engine itself but the game is still stored in the browser (in the localhost domain).

I know this whole storage situation might be confusing it's not a very obvious system :d

Anyways, I hope I have answered your questions to your satisfaction! Unfortunately I am not developing trash engine very actively right now for lack-of-time reasons, but seeing the issues you run into gives me a good idea on which parts of the engine to improve when I get around to it! :>

(Also I'm on on my phone right now, but I will check out the mod, when I'm back on a computer)

window.blablabla works! Thank you! Yes, i saw rooms transitions, pretty smart, tho i improved it by also using "roomName+x+y", so for example if you are in room "badfgdf_0_5" and you go somewhere, you go in "badfgdf_3434_439, so prefix stays." "upgrade()" is function, which i saw in gameName.html (after "export game"), it's in start, and it's name and code make me think that it upgrades game to newer version. I can try to change ID, but idk if that would work :p. Probably if i'll change it then it will be disconnected from trash engine (right what i need), and you should add option "change ID on export to:" in settings :>

Oh, i'm not sure which Id to change. When i use search, there are a lot of Id, but i don't think any of them is right. You said "can change in settings", but there is nothing about id. Ig Id is project name, which you can change it top. Only problem is what when i'm trying to search for it, vscode lags, cuz all data is in one line >_< Ig i will try to change project name, export, and change it back lol. Probably after that best solution is to do changes in one Id, and when everything works correctly/when i want to release new version i should change project Id and save it lol. idk.

Developer

Sorry it took me a while to respond. It turns out the game id is a feature that I only experimentally tested out on my machine, but never fully implemented, sorry >.< The "different games sharing the same save data" is a problem I have been aware of, but my brain remembered me fixing it, when in reality the version on itch still has this problem. So the save data problem is 100% a bug, I will try to fix it soon!

The upgrade coming from gameName.html makes sense, this file contains a lot of generated code (I'm using a web framework called svelte), and the upgrade funtion comes from the framework, not from me. The exported file is really not meant to be edited directly. If you really need to change things there, the section of the html within the <script type="gamedata>..</script> tag contains the entire game, the rest is just the engine.

That being said, there should be a place in the html thats says:

const NAME = "trash_engine";
const STORE_NAME_RESOURCES = "game_data";

Changing any of these strings to something else might work, but I haven't really tested it.

No, i changed project name it still updates. oh no.

Wait, i just thought.... If it's stored in browser... then maybe it updates only for me???

Developer

yes, generally this should only happen on your machine + browser. Other people will just see what's uploaded on itch (or with this bug theoretically maybe also a different game that they've been working on)

(last one shouldn't happen because i can play your game just fine) Thanks for reply!