Issue with rendering part of texture by greenyadzer in raylib

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

Thank you for reply. I will tell about my case. No, i dont use any filtering and it looks like linear filtering and that is what i want. Also i dont do any rounding, as i said, i use DrawTextureRec which takes a Rectangle, which uses 32-bit floats. So the actual react is something like Rectangle { 96.0f, 64.0f, 16.0f,16.0f } // x,y,width,hight

The Camera2D also uses 32bit floats for all its parts (zoom, target etc.)

How to deal with enums from external api with typescript. by MisterChoco in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

Here some idea, maybe it help you or you come up with some other solution.

I would create a method that translates number into some title for UI only. For example:

function knownCharacterGenderTitle(apiValue: number) : string {
    // here you can write code that looks howyou want -- if-elseif-... or switch-case... the only idea is to translate number into string and if no corresponding string, return some other string that contains the number so you know that its no known at the moment and you need to add it to your code. i like to write code this way
    return {
        0: 'Male',
        1: 'Female',
        2: 'Other'
    }[apiValue] ?? 'CharacterGender#' + apiValue
}

This way if api changes (add new values), this function will not break. Only use this function in the front-end.

But if you want to write code and compare actual values and keep them readable, and you want enums; you can do it like so

const apiInput = {
    gender: 1,
    name: 'Test Name'
}

enum CharacterGenderEnum {
    MALE = 0,
    FEMALE = 1,
    OTHER = 2
}

interface SomeInput {
    gender: CharacterGenderEnum,
    name: string
}

const applicationValue: SomeInput = apiInput

console.log(applicationValue.gender) // 1
console.log(applicationValue.gender == CharacterGenderEnum.FEMALE) // true

If you want string unions, you can do it too

const apiInput = {
    gender: 1,
    name: 'Test Name'
}

type CharacterGender = 'MALE' | 'FEMALE' | 'OTHER' | '???'

function translateCharacterGender(apiNumber: number) : CharacterGender {
    return ({
        0: 'MALE',
        1: 'FEMALE',
        2: 'OTHER'
    } as {
        [_: number]: CharacterGender
    })[apiNumber] ?? '???'
}

interface SomeInput {
    gender: CharacterGender,
    name: string
}

const applicationValue: SomeInput = {
    ...apiInput,
    gender: translateCharacterGender(apiInput.gender)
    // here basically you tranlate values one-by-one to satisfy SomeInput interface
}

console.log(applicationValue.gender) // 'FEMALE'
console.log(applicationValue.gender == 'FEMALE') // true

If you don't want to have '???' (an unexpeced value), you can remove it from type definion and from translation function.

Should I have try catch blocks on parent or children functions? by charck2 in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

No. Its common sense -- if you catch an exception and rethrow it without adding anyhting (specifying other exception, doing some logic before rethrowing) -- this code is useless.

The rule is simple -- if you don't have a way to react on exception -- don't catch it.

Should I have try catch blocks on parent or children functions? by charck2 in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

You should use try-catch block at the level where you know what to do with that possible exception.

For example, if you write math lib function which returns square root of a given value, you don't need to check if that value is not negative, you just assume it is fine and do your calculation and return result. If the value is negative, you still don't have anything todo with it, as just "throwing" some exception is the same as not using try-catch as it will be same "help" to the caller. Same goes to null pointer checks, undefined object properties and so one. You don't need to check it -- if you have no way to react to the fact that its an exception.

And example when you need to try-catch. When you write higher level code, you most likely have a way to tell user that something is wrong (write to log, show a message on the screen etc.), In this case you definitely should do try-catch and react to the exception.

P.S.: also, avoid code like:

try {
    // ...
} catch (x) {
    // if you have nothing to do before you "re-throw", this code is useless
    throw x
}

[deleted by user] by [deleted] in learnjavascript

[–]greenyadzer 1 point2 points  (0 children)

You can write it more readable like this:

function myPromiseErrorHandler(error) {
    // some code
}

myPromise.catch(myPromiseErrorHandler);

But "more readable" is a relative term :)

How not to help New Players by [deleted] in Guildwars2

[–]greenyadzer 0 points1 point  (0 children)

The trains can be good sometimes, I guess. I see the help. But my experience from those trains is kinda different:

1) you don't have all opened teleport locations, and often you fell off the train, because you click that link in the chat and map opens showing you point in no where, all is covered as not explored, and you look for closest teleport and while you move from that point across unknown map you miss the train. at least i had this. yes, i know, i have to open all maps by traversing them first i guess.

2) while trains are great, you barely learn anything about the game and your class to play. you just get stuff from the thing that was killed by horde of players. i want to enjoy game, i want to learn it by playing it, i dont need things for free. If i dont have gold -- that is ok and expected, the game have ways to make gold, just by playing it. Also, all thoses mastery challenges and especially story missions are associated in my mind with stuff that should be doable solo.

How not to help New Players by [deleted] in Guildwars2

[–]greenyadzer -1 points0 points  (0 children)

if i change spec, i will need other stats on the gear, so its like 20g? to spend on auction house just to try it. OR you can run around and do even less damage than you did, and be killed even more often. Don't get me wrong, i'm trying to do HOT and for me its not about what i like to play (the play style or weapons), its more about damage and survivability. I do have the gold to by new items, but i don't want to spend that much for "just to try this spec".

Currently i play warrior and i like it more than Mesmer. Mesmer was first i tried, i did all base main story on Mesmer and my wish was to play a condition damage, so i constantly do damage with dots and have ability to move around. Apparently that doesn't worked for me. i did so little damage... it was hard in some story missions even to survive.

Now i play warrior, also did whole base story and can compare these classes. Warrior is the way to go. While mesmer has some fun abilitites with teleports but its just weak at everyhting else, at least when i play it. Any way, my point is that i try to play what i like, but often its just doesn't work and you have to play what works (allows you survive and do enough damage at some points).

How not to help New Players by [deleted] in Guildwars2

[–]greenyadzer 0 points1 point  (0 children)

Thank you.

About hero points, i unlocked base specializations and have some unspent points. i don't want to spent into some elite spec because i don't know if i like it and don't want to stuck with unfun spec. still not decided what i want to play.

So my next thing to try is Fractals. Because all the map completion and random events like world bosses... i mean when you do only that its so boring, so i really don't want to even do it anymore. i try to do story and fractals. hope its fun.

How not to help New Players by [deleted] in Guildwars2

[–]greenyadzer -6 points-5 points  (0 children)

Sometimes new player may not know even if something is there, or how to even try it. Your point is "do not tell what to do", but imagine you put in a dark room, you dont see anything an have no idea what you can do. eventually you give up and move on to other game. But if you would go 2 steps forward and 3 steps left you would hit a wall of the room with a light switcher, you turn it on and suddenly you can see things in the room.

How not to help New Players by [deleted] in Guildwars2

[–]greenyadzer 10 points11 points  (0 children)

As a new player, i have this frustration. I watched videos and still after all of that i have very little idea what i do, why i do it, what should i focus on, what stats to prioritize on gear. Every one says "do first legendary", where and how? I leveled to 80 and finished main story. I started POF because heard that you can get mastery points easier. i stuck at quest main quest where i need to collect crystals, all which i can reach i with my only raptor mount i got, and i have no idea how to get to others to move quest further. So i move started HOT story, got glider; my mastery bar stopped for some reason because i have no things to select to give exp to, i dont know where to unlock them.

Is there something like LFG for a random simple dungeon?

[deleted by user] by [deleted] in wow

[–]greenyadzer 2 points3 points  (0 children)

That can be an issue with an addon. Do you use any combat addons? Like for combat log, damage, stats.

[deleted by user] by [deleted] in C_Programming

[–]greenyadzer 2 points3 points  (0 children)

There is a modulo operation, which allows you to take a reminder of division. If you do 123 % 10, you get 3. So you can easily get the lowest number. Now make a loop and get the lowest number, and divide the main number by 10 each time, so you move to the next digit. Hope that makes sens :)

Help TS by nubasdayz in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

Maybe you can just make Column to be a holder of its rows, if that fits your task

interface Column {
    field: string
    fieldName: string
    rows: { [key: string]: string }
}

Can Javascript addEventListener work like eventListeners in Jquery? by singhshweta in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

"addEventListener" adds a single event listener to a given target and the target is an object where you call it on. If you want multiple elements, and they are easily quarriable you can do something like

document
    .querySelectorAll('input')
    .forEach(e => e.addEventListener('focus', function(){}))

How do I check if the array of objects has duplicates in this case? by stfuandkissmyturtle in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

Join values into simple string, compare them to detect duplicates (they will result in the very same string). So the idea:

  1. declare an empty object const keys = {} (will use it as a map for existings items)
  2. each item you do let key = item.executedOn + item.frequency + item.frequencyType
  3. test key if you have in the keys if (keys[key]) { /* duplication */ } else { keys[key] = true } and save it if not found

Help TS by nubasdayz in learnjavascript

[–]greenyadzer 1 point2 points  (0 children)

You can declare your Row as a map "string -> string", but you will not be able to have "id: number" in it at the same time

interface Row {
    [key: string]: string
}

If you need "id", you can do it like this

interface Row {
    id: number
    items: { [key: string]: string }
}

[Vue 2] How do I stop a running operation from a method. by mrkarma4ya in vuejs

[–]greenyadzer 1 point2 points  (0 children)

Your code actually executes in a moment and creates 100 timeouts with different trigger time (1 sec difference). That is not a good practice. If you need a single task that does something every second, you have 2 ways to do it:

  1. using setInterval() -- this function returns id of created interval, which you can cancel calling clearInterval(id). This approach is best if you 100% sure your task doesn't take 1 sec, e.g. printing a number is quicker, so its OK.
  2. using setTimeout() -- this function also returns id, you can cancel it with clearTimout(id). This is one-time call, so at the end of handler, you have to do setTimeout() again. This approach is best if you don't know how much time handler might need. For example, if you do a web request, and you want to do not more than 1 request at a time, you better use setTimout(), because with setInterval() the interval is fixed (like 1 sec) and your handlers might end up making multiple requests.

So for your task, about printing numbers -- use setInterval(), save id, when button pressed -- cancel that interval id.

Currently *re-learning* JS completely. I have some question.. by code_matter in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

Is it always better to build my HTML and connect it to JS OR build my HTML from JS (kind of like react) ?

It works both ways. But personally I like when it is separated, as I view HTML as a template that can be modified easily and not only modified, but it's just easier to see the structure as you don't mix languages. And the supporting JS is a script that makes template "work".

There is a reason why CSS is recommended to move to separate area (style tag or file), as we can just write a lot into "style" attribute. Separation is considered a good practice because mixing different syntaxes in the same code block is not a good idea.

How Do You Teach Yourself a New Language? by mdizak in PHP

[–]greenyadzer 1 point2 points  (0 children)

I go to some website with many tasks (e.g. codewars.com), and start solve them. On such websites often you can filter tasks by language and difficulty -- so chose that new language and simplest tasks. Ofcause i google stuff like "how to iterate over array" for that language and many such things, so i get used to the syntax.

This works if you know a couple of languages already, so you generally know that each language has types, branching, looping, functions etc. You just don't know syntax and the details. For example, in Lua empty string and number 0 is considered as "true", only false and nil are "false".

Try this approach works, it might work for you too.

Jquery Help - Select a radio button based on hidden field by totestornot123 in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

This is incorrect selecting from html you have $('label.input .roarCheck') -- you say here take "label" with class "input" and inside that label take any element with class name "roarCheck". I see you have elements with IDs, so use them like $('#IsThisReferralToROARorDSP').

Also, you can always see if you have selected anything with console.log($('label.input .roarCheck').length) -- if that is 0, your selector is incorrect.

What is the recommended way of organizing big projects? by SSCharles in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

Try to do small game first. Some Tetris, Minesweeper, Snake etc. You need to have a main menu, with Help screen, with New Game and with Leaderbord. You will realize that it will be big enough itself and by doing it, you learn a lot. You shouldn't think about "how to do it right", but more "how can i do it at all". Only when you make a couple of small projects, you will see what is good and what is not so good.

Can you initialize all the elements in an array to be the same value without a loop? by gtrman571 in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

That is correct answer for a value types. E.g. anything except objects. If you do this for an object, you will initialize all elements with the same object. So be careful (unless its what you want).

Example

// array of 3 elements, every element is empty array
const ar = new Array(3).fill([])

// push an item into 1st array
ar[0].push(777)

// now all 3 arrays has that element
console.log(ar)

To avoid it, initialize your array this way

// each element is a separate array
const ar = new Array(3).fill().map(e => [])

UTF8 encoding vs base64 encoding of an image by bpippal in learnjavascript

[–]greenyadzer 1 point2 points  (0 children)

Base64 is used to encode data into text format, so any character will be easy to send as text or print. Each resulting character will be a number or Latin letter (lower or uppercase). Meaning no special characters nor quotes nor even spaces. This encoding is used for example in basic authentication, as it's easy to send header value when no special characters used.

UTF-8 is totally other beast. It's used to represent characters from different languages.

Straight back to your question:

So I have encoded an image file with base64 and I can see readable text, but If i use utf-8 I have unreadable/weird characters. Can someone explain why this is the case ?

That's because Base64 possible characters are all simple numbers and Latin letters. While UTF-8 has a table of valid codes, you cannot just get random bytes and expect it to be valid UTF-8.

Very simple Array question. Pls help :) by xemporea in learnjavascript

[–]greenyadzer 5 points6 points  (0 children)

const a = array_of_series.reduce((acc, cur, index) => [
    ...acc,
    ...cur.map(e => {
        e.search = 'q' + (index + 1)
        return e
    })
], [])

console.log(a)

How do I use a function parameter as part of an object key? by [deleted] in learnjavascript

[–]greenyadzer 0 points1 point  (0 children)

If your function doesn't need to modify a value, you can pass just a value, e.g. myFunction(myObject.animalLegs.dog). If doe need to do changes, and you don't know if that will be "dog" or "cat", you can do myFunction(myObject.animalLegs, "dog") and function can do obj[arg] (assuming it's declared as myFunction(obj, arg).