|
ok so I am a baby, on a webpage, what's the accepted way to do an infinite loop this page is a game, a idle game, so I am constantly calculating countdowns etc
|
# ¿ Jun 5, 2022 11:00 |
|
|
# ¿ May 13, 2024 20:15 |
|
so in this game, I have a bunch of "things" to do, which are represented as buttons, and I add then via js I have a function that makes a button element, gives it a few properties, and the uses getElementById().appendChild() to add the button into the flex box it works, but one of the things I am trying to add to the button before I put it in the box is an event listener and it just aint working. I even wait until I have appended the button into the flex container, then using getElementById().addEventListener() but it just doesn't work, and it doesn't show up in the inspector's event listener thing. Is there something I need to know about this? is it becasue it's been made from inside a function called by a for each loop? because that's why I try to add the event listener after it's been appended
|
# ¿ Jun 7, 2022 12:20 |
|
fakemirage posted:Do you have any code examples you could post where adding an event listener doesn't work? code:
at the moment this code is meant to put the name of the button, which is also it's id, into another box. I'm just trying to get the button working. Appreciate any help. echinopsis fucked around with this message at 19:33 on Jun 7, 2022 |
# ¿ Jun 7, 2022 19:31 |
|
yeah I noticed it was being called immediately, but wasn’t sure why. Thanks mate it does seem odd that it calls it, but suppose that’s my immature understanding of js
|
# ¿ Jun 7, 2022 20:12 |
|
That'll probably come in super handy considering what I am trying to do, which is basically a spin on an idle game. Thanks
|
# ¿ Jun 8, 2022 12:16 |
|
reversefungi posted:The addEventListener function registers a callback function, whose execution is delayed until everything is exhausted in the main thread and you've entered the event loop. However the "registering" happens on that main thread, and in this case you were invoking a function and registering its output, hence the immediate call. I watched this video and I think now your post makes more sense to me lol.
|
# ¿ Jun 9, 2022 12:08 |
|
fakemirage posted:Haven't gone through everything, but I noticed the following line. I've been looking and trying to understand arrow functions, and I can't work out why changing it to an arrow function works? when you post: JavaScript code:
why does code:
|
# ¿ Jun 10, 2022 01:31 |
|
wow guys poo poo you’ve given me a good series of answers. I won’t have a chance to sit down and get my head around it until tomorrow, but gosh I really appreciate your help and support here. I feel like I am making a lot of break throughs, where my time is leaning more toward making progress on my program rather than spending time trying to work out how the heck I do anything
|
# ¿ Jun 10, 2022 04:29 |
|
alright thanks guys. I really do understand now why my original code was failing. the notion of arrow functions is less intuitive to me, but I am working on that. thanks again. good old something awful huh
|
# ¿ Jun 12, 2022 03:46 |
|
at some stage while working on this I must have made a change and I don't know what, but I am unable to work out why a css selector isn't working on a div when I inspect it in chrome, it's clear it's got the class on the div, but it's like the css isn't even there in my stylesheet. it's not like it's being overridden, just doesn't seem to be working at all. I have this at the end of my css file code:
you can view the source at http://crimecommitter.com
|
# ¿ Jun 13, 2022 14:20 |
|
oh my god what a fuckin numbnuts thanks guys
|
# ¿ Jun 13, 2022 20:43 |
|
yeah 2 experience . that’s um not a typo lol next step is figuring out date() i’ve just tested positive for covid so guess i have a week at home to work it out lol
|
# ¿ Jun 13, 2022 23:08 |
|
day.js it is then given how important it is to my game, i’m happy to use a library if it makes my life work
|
# ¿ Jun 13, 2022 23:50 |
|
this day.js is very good, but I need relative times, which it can't do without a plugin, which requires "require" lol, which is a node thing, and probably needs a plugin to make it work in browser. I might go with date-fns since it's not minimalist and hopefully means one package will be enough
|
# ¿ Jun 14, 2022 01:12 |
|
echinopsis posted:this day.js is very good, but I need relative times, which it can't do without a plugin, which requires "require" lol, which is a node thing, and probably needs a plugin to make it work in browser. poo poo this is driving me crazy. is it normal that everything assumes you're running node? at least the dayjs was straightforward, it worked well until I couldn't figure out how to include plugins anyway, it's a slow road trying to get something as basic as datetime working it seems. e: have worked out half of how to import plugins with dayjs into the browser without required node or whatever. thanks for reading echinopsis fucked around with this message at 02:21 on Jun 14, 2022 |
# ¿ Jun 14, 2022 01:55 |
|
camoseven posted:You usually want to use import for front end apps, though you can load scripts directly as indicated by the DayJS docs. I'm trying that final method, and the tricky part seems to be the dayjs.extend(); I don't seem to be able to paste source stuff into this but basically I script src https://unpkg.com/dayjs@1.11.3/dayjs.min.js script src https://unpkg.com/dayjs@1.11.3/plugins/relativetime.min.js and then dayjs.extend(relativetime) now that plain didn't work, so I tried extend(window.relativetime) and that seems to work.. except it seems to be finding a problem code:
e: but I finally got it working, I copied the scripts into my own folder and discovered I needed to extend day.js with dayjs_plugin_relativeTime not something else. which I only found by looking thru the relativetime.js maybe I am dumb but I am not sure why that's not clear on the docs that you need to reference it like that, copying and pasting their stuff just didn't work. NOW on with the show echinopsis fucked around with this message at 02:56 on Jun 14, 2022 |
# ¿ Jun 14, 2022 02:42 |
|
camoseven posted:Capitalization matters for the extend, it's relativeTime this didn't work, and neither did window.relativeTime, wasn't until I did the "dayjs_plugin_relativeTime" that it worked thanks though. slowly hacking my way thru this
|
# ¿ Jun 14, 2022 02:57 |
|
once I got over being mad at the less than obvious (for me) way to add the plugins to dayjs and got my head around it, it all ended up running smoothly. thanks to everyone for their patience with me lol. the games called https://crimecommitter.com and no it’s not very good but at least it kind of works without being buggy and next step is flesh out the crime content
|
# ¿ Jun 14, 2022 13:28 |
|
Hi, I've run into some confusing activity here. so JavaScript code:
https://twitter.com/_crimecommitter/status/1537339000884953088?s=20&t=ZUgBbHaQLHz6uzWthzrg7A at first the function returned the string and it had the same problem. then I thought I'd just abuse global variables so I do it that way, but the same problem. In the console, if I access the variable it returns the correct string. It wouldn't be so weird except it works if I just put that code into the original function. e: fixing that next problem fixed this lol echinopsis fucked around with this message at 09:52 on Jun 16, 2022 |
# ¿ Jun 16, 2022 08:56 |
|
Also this also confuses me ok so setOfAccumulatedData is an array of a function, which has the variable numberTimesCommitted in each function. I am using the function basically as a struct since javascript doesn't have structs BUT JavaScript code:
I can't work out how the heck e: I create the function like this JavaScript code:
code:
it's like there is only one numberTimeCommitted variable rather than one per each in the array e2: I have fixed it, but only by expanding my initialisation method, and just expanded it, but it feels messy, and I'm sure the problem is me misunderstanding how to automatically make an array of functions e3: I just expanded it to this: JavaScript code:
echinopsis fucked around with this message at 09:38 on Jun 16, 2022 |
# ¿ Jun 16, 2022 09:16 |
|
Jabor posted:This code: this is what I am doing : code:
my "background" if you will is unreal engine and so I work things how I worked them there Jabor posted:This code: yeah I suspected something like this was happening
|
# ¿ Jun 16, 2022 13:07 |
|
O yep I see I actually have a CSV file with that data in it that I use a hacky python script to that outputs to a file that I copy and paste into my code, so that over time it's easy for me to add more crimes without fiddling in the code. I could probably work out how to have a separate data file lol.
|
# ¿ Jun 16, 2022 13:53 |
|
Thankyou. I’ve enjoyed the whole process and even come to like javascript lol. I’m certainly proud of how far I’ve come, and I thought I was going to have to spend a day working out cookies and I managed to knock it out in a few hours, the best part being the section where I combine an array into a single cookie (by joining them into one string with “;”) and then later pull them apart with split, I managed to write all at once and it all worked. I know I’m getting better when I can write entire sections that work first try. I did have other problems with cookies though and it didn’t help that I couldn’t debug them without uploading to the website but managed to get it working. The game is highly functional now, and just needs me to put some decent time into making a decent list of crimes to do. which weirdly I fine quite difficult. BUT no excuses, and I have 6 more days off due to covid so I should be able to get it done. And there is definite work on the css left to be done lol. while a small amount of jankiness contributes to its aesthetic, I defo need to make it work on more than just full sized desktop screens. and link to a merch page or course. lol With cookies now working, it’s feasible to have crimes that take days and weeks to complete* and also should be able to update it and add to it without breaking it so in theory there’s maybe interesting things for people to come back to * I don’t use any kind of countdown per se, I just encore the end datetime the moment you hit go on any particular crime, so it doesn’t matter if you close the browser, and when you come back it’ll recalc their state so you’ll come back to completed crimes ready to collect I’m quite “excited” about making some other websites though. A major step would be logins, and I understand using something like django would take a lot of the hard work out, except at the moment it’s 100% client side and hosted at github and so I am sure if I took the next big step of having logins it’d mean quite a significant change. although it would allow me to email people to tell them they’ve got uncollected crimes. ugh there is always scope for adding features lol Thanks to everyone in this thread who helped, you’ve all been helping and the fact you were so willing to help also meant so much.
|
# ¿ Jun 16, 2022 20:47 |
|
Osmosisch posted:Agreeing that following your progress has been fun! Thanks for the tip, I'll look into it tbh I don't mind paying some money either. I've offered a local comedian $100 for an hour or so work to write up some paragraphs for the crimes, to provide incentive to play deeper and deeper
|
# ¿ Jun 16, 2022 21:13 |
|
seeing as I've hired a person to write me up some descriptions etc, I suppose it would be wise to store these in a data file, now I've been looking around, is JSON the best format to use for this? will it have trouble with commas etc? (spose I can always encode those somehow) because it makes sense to me to store this data, which will be large character wise, in it's own file and keep the javascript file clean. and I could store all that information that I declare into my function in the data file, and if it's json then it's designed from the ground up to be readily read by javascript, right? The other day I was thinking about storing it in csv, but then I'd need a special way to convert out of csv, but if it's json then it's kind of ready to go? am I understanding that correctly? I could easily make a for loop that cycled through all the json entries and fill up my setOfCrime array? or as I am writing this, perhaps even skip that step and directly reference the json file where and when I need to instead of an intermediate array of structs? Initially my setOfCrime array was carrying mutable gamestate data but I've moved that into it's own array now so the setOfCrime array is read-only anyway, could I entirely skip that step and read from the json where and when I need it? Or would it still be wise to have that intermediate variable hanging around in memory or not for performance reasons*? *because I tell you what, my code is NOT efficient lol, I know I do a lot of inefficient refreshes for the sake of making it easy to code and think about. every single page redraw (however many times per second that is) checks every single crime to see if it's finished, updates the time on it, refreshes the top banner, the current time. When I have more crimes to do, spose it might be prudent to reduce this to every half second or so. seeing as it's not my cpu cycles I'm using doing this lol.
|
# ¿ Jun 16, 2022 23:35 |
|
Thankyou, that certainly settles it for me that I'll use a JSON file to store all this data. I'll probably keen defining the array in my main code, just directly reference the data in the JSON file, and try to format the data in the JSON file exactly as I will be using it in my code.
|
# ¿ Jun 17, 2022 01:43 |
|
can I ask a question about JSON I'm trying to hold all my crime data (read only stuff) in a JSON file, and I am unsure of how to have the layout. my goal would be to access it like code:
code:
am I heading in the right direction?
|
# ¿ Jun 18, 2022 23:31 |
|
roomforthetuna posted:That's a fine layout, though why a json file rather than a js module? oo I never saw this although I am thinking about importing a csv library and parsing a csv file at runtime because it’s much easier for me to maintain the data in excel and export to csv when I’m done and then that’s it, not another step Analytic Engine posted:Looks good, just drop the two lines with } and { after crimes and put a comma there instead. Those are keys in the object about dictionaries I finally worked out how to use them for ordinary key:value pairs but what I want to know is if I can use a dictionary so that I can access a handful of variables via the dictionary key. eg code:
code:
code:
I realise I’ve coded some stuff very poorly, and if I could create data structures that used keys to access them it’d be incredible
|
# ¿ Jun 27, 2022 22:09 |
|
I used a basic dictionary for some functionality I recently added and man it just worked so easily lol
|
# ¿ Jun 27, 2022 22:14 |
|
Doom Mathematic posted:echinopsis, you need someone to pair program with for an afternoon. I had literally thought about something like this, even paying someone for a couple hours or something, help me crack open some of these awful implementations of mine. Video Nasty posted:Object.keys() will let you iterate over the JSON object and you can pull from that. Echi I can provide assistance for you tomorrow but I'm not on NZ time. I appreciate this, but it is a bit of a challenge to find a time given I've got kids and work and squeeze this in just when I can, but I might take you up on this if at some stage, if you're still keen and willing.
|
# ¿ Jun 28, 2022 09:35 |
|
|
# ¿ May 13, 2024 20:15 |
|
e:dw
echinopsis fucked around with this message at 09:11 on Jan 24, 2024 |
# ¿ Jan 24, 2024 08:47 |