Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
jestdotty624420dvideo games use state machines a lot. like (classic, video game NPC) AI needs to be states like "idling" and "attacking" or "flee"
I'm making something similar. except some moves can be done in the same turn, and this is a competitive MMO against other programmers lol
so it has to have multitasking and also checking when you can't do any other potential states you can go into -
lorentz1532420dWe have a similar feature, but implemented more transparently.
There's a search criterion list, and when you hit enter in the search field, it clears the field and adds its content to the criterion list. The contents of that list are introspectable. On any keypress, the search results are produced via all of the criteria, including the contents of the search field, if it's a meaningful filter. -
lorentz1532420dI'm not convinced that this needs a state machine. State machine is a good model for situations where the way each element is processed and not just the numerical result is dependent on the previous section of the list. Even a typical reduce or fold isn't best modelled as a state machine if none of the information produced by the body selects an execution path in later calls to the body.
-
lorentz1532420dState machine is a super general model, pretty much the only thing you're promising is that the subset of state that selects an execution path on the next iteration is bounded. you should generally either choose a more specific model or try to phrase your code more directly. This description sounds like you can just put the filters into a list and fold that list into the list of results (in JS fold is the 2-argument form of Array.reduce)
-
CaptainRant427520dTo be specific: as a mediocre programmer I often struggle with state in semi-complex situations. Highly-interdependent states, keeping logic in your head.. it's all a bit cloudy sometimes. You want to save state A, which depends on state B, and you think you're going to keep it all in memory by adding it into a temp state C, but then state B depends on A and A depends on C and quickly, you're going crazy in your mind, losing oversight of the code.
Solution: study algorithms and computer science better. -
CaptainRant427520d@jestdotty amagad jest, so hawt. Yous the cools.
Permutations, innit? Accounting would be fun because then you already have the model ready.
Thanks for the explanationz and the enums tip. -
CaptainRant427520d@lorentz A criterion list. Interesting approach. It also decouples the searching from the criteria. Very nice.
-
CaptainRant427519d@jestdotty Accounting for when data doesn't exist is what I sometimes find hard because you have to know what you're going to do first.
I see the hierarchical logic there.
I worked with passport.js and the classic access_token and refresh_token in the past before, security wise. I prefer keeping things non-async and few API's if possible. -
CaptainRant427519d@jestdotty /ignore jestdotty -thinkingoutloud -jk. I appreciate a creative mind!
-
CaptainRant427519d@jestdotty I know, I knowwww, JS is loosely typed. -inner joke lol
JavaScript sounds like your thing and Rust sounds rusty. It always makes me think of that videogame...
Related Rants
What is your method of dealing with states in state machines? In programming, we often come across situations where we have to model states in our head as to not get the programming wrong, e.g. in my case right now:
You have a tabular webform that gets filled in.
Requirements:
- When the user is able to search the data for a specific value, it should be a cumulative search (e.g.: search for books with "eng" in the language and then with with "19" in the publishing date)
And so the current pseudocode is:
search(e) {
if(!word) {
set(previousState);
}
const searchdata = previousState.filter((row) => row.indexOf(word) != -1);
// but wait, what if I say: searchdata = searchdata.filter() for cumulative search? Oops, I can't, because it doesn't exist at that moment yet. What if I create another variable?
setState(data: searchdata);
}
Current bug:
- when deleting characters from the search field, it doesn't filter cumulatively; it just filters the data according to the current filter.
It's things like these that get me stuck sometimes.
question
state
logic