<FromGitter>
<bew> ECR is a templating system that works at compile time, here `page` is only known at runtime (when you run your program) not at compile time @everdev
<FromGitter>
<bew> If you need a runtime templating system you need another tool, like crinja
sagax has quit [Remote host closed the connection]
<FromGitter>
<asantebuil> well i want an array back but locally on my machine its not allowing map. It's giving me " undefined method 'map' for String"
<FromGitter>
<asantebuil> nevermind i see
<FromGitter>
<bew> ^^ the relevant bits was `for String` :)
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter>
<asantebuil> it seems to be a weird scop issue. im coding a bot, i have a leaderboard variable as a hash thats at a top level. i then have a client.on event listener and inside the listener is a case statement
Yxhuvud has joined #crystal-lang
<FromGitter>
<asantebuil> i am calling leaderboard in one of the when statements. however if i were to unhoist leaderboard and put it into the local statement it worksa
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Client Quit]
<FromGitter>
<sherjilozair> Assigning a variable to `Random.rand` works, but assigning it to `Random.rand(128.0)` gives a type inference error. Is this a bug? https://play.crystal-lang.org/#/r/3y5w
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
pabs has quit [Ping timeout: 256 seconds]
pabs has joined #crystal-lang
Raimondi has quit [Quit: WeeChat 1.9.1: ¡Chau!]
aarongodin_ has joined #crystal-lang
avdi_ has joined #crystal-lang
Majost_ has joined #crystal-lang
jetpack_joe_ has joined #crystal-lang
early` has joined #crystal-lang
Raimondi has joined #crystal-lang
g-glitch has joined #crystal-lang
Majost has quit [Ping timeout: 256 seconds]
early has quit [Ping timeout: 256 seconds]
avdi has quit [Ping timeout: 256 seconds]
aarongodin has quit [Ping timeout: 256 seconds]
briank has quit [Ping timeout: 256 seconds]
braidn[m] has quit [Ping timeout: 256 seconds]
jetpack_joe has quit [Ping timeout: 256 seconds]
swav has quit [Ping timeout: 256 seconds]
Majost_ is now known as Majost
aarongodin_ is now known as aarongodin
avdi_ is now known as avdi
jetpack_joe_ is now known as jetpack_joe
swav has joined #crystal-lang
betofloresbaca[m has quit [Ping timeout: 246 seconds]
byteflame has quit [Ping timeout: 246 seconds]
olbat[m] has quit [Ping timeout: 240 seconds]
Renich has quit [Ping timeout: 240 seconds]
thunker[m] has quit [Ping timeout: 255 seconds]
cptaffe has quit [Ping timeout: 260 seconds]
kixune[m] has quit [Ping timeout: 256 seconds]
fifr[m] has quit [Ping timeout: 255 seconds]
kp666[m] has quit [Ping timeout: 276 seconds]
<FromGitter>
<bew> No, I think that's because the return type of that method is not specified.
<FromGitter>
<bew> In general you should not rely on that, and should always manually specify the type like : `@a : Float32`
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter>
<bew> @asantebuil if you're trying to access a local variable at toplevel, from inside a method, then it's expected, you can only access local vars from the method, not outside of it
Yxhuvud has joined #crystal-lang
<FromGitter>
<girng> im not sure if anyone saw my example i posted last week of creating 370k classes, but memory stayed around the same. would that way be the right thing to for monster generation in maps? players will be able to create a map, and it'll select amount of monsters to spawn in the mob at certain positions. im thinking 100 or 200 per map dependent the map size. (all will be randomly generated) ⏎ ⏎ so.. my question
<FromGitter>
... is do i do an Array of NamedTuples for the monsters inside the GameServer class, or just do an Array of "Monster" Classes?
<FromGitter>
<asantebuil> @bew yeh everything was solved when using class instance variables, i was really lazy and didnt want to convert a simple example to a class but i did anyway
<FromGitter>
<asantebuil> its much better now
<FromGitter>
<girng> Monsters will only need properties (or keys) of current_health, position, damage, a few others
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter>
<girng> Each game instance server will be using those $4.99 cheap vpses, so i'm thinking around no more than 100 players will be on per instance. so the array of monsters in each game total will be around 20,000. that's assuming if all 100 players each have their own map and not playing with others
<FromGitter>
<girng> `for the monsters inside the GameServer` class. I mean Game class, not GameServer
<FromGitter>
<sherjilozair> @bew `Random.rand` actually has `Float64` specified as the return type. There's no ambiguity. And even if there is why can't it infer the type as `(Float32 | Float64)` or `Float`. If I have to specify all the types, then Crystal has little point.
<FromGitter>
<sherjilozair> @girng Which framework are you using for this game?
<FromGitter>
<girng> godot engine, with a crystal TCP server as the back-end
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter>
<bararchy> @girng Monster class will allow you to add and enhance while keeping same type reference all over the code
Yxhuvud has joined #crystal-lang
<FromGitter>
<girng> Okay sweet. Monster class it is then! Let's GO!
<FromGitter>
<sherjilozair> @girng Didn't know it was possible to use Godot with Crystal. How are you doing this?
<FromGitter>
<sherjilozair> Wait, so you're using crystal just for the server code, right? The client code is still in GDscript?
<FromGitter>
<girng> yeah!
<FromGitter>
<girng> it's all read/sent as individual messages too. no need to do your own custom "\n" package parsing stuff (that i was originally doing with nodejs lol). very nice
<FromGitter>
<sherjilozair> I see. Pretty cool. Is this an MMO-type game where most of the computation is in the server?
<FromGitter>
<girng> well, just player movement and inventory, stashing, updating / saving skills, using a skill, chatting, lobby join leave, passive tree update, equipping gear. coincides with `db` module very nice
<FromGitter>
<girng> but most of that is for the master server, my game instance server will have other stuff too. but it's instance based
<FromGitter>
<girng> 6 players per game, spawn then in fibers on $4.99 VPSs 😂 LOLL
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter>
<schoening> In VSCode I seem unable to set the indentation to 4. Is this intentional? I know crystal and its devs are very opinionated but forcing indentation :/ ?
Yxhuvud has joined #crystal-lang
<FromGitter>
<schoening> Could be a bug in vscode, but I figured Id ask coz I dont see any settings issues that I made.
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
<FromGitter>
<bararchy> @girng that's really cool, you should blog post about how you integrate with Godot
<FromGitter>
<bararchy> It could interest a lot of devs
<FromGitter>
<girng> yah, maybe one day. thx for support.
<FromGitter>
<bararchy> @sherjilozair intemediate array is not an issue if it's something you actually use :) ⏎ also, it makes sense for some usecases where you can't avoid it
<FromGitter>
<bararchy> or in other words, don't kill your-self over it XD
<FromGitter>
<sherjilozair> I see. Thanks @gdotdesign @bararchy
DTZUZO has quit [Ping timeout: 255 seconds]
moei has joined #crystal-lang
jokke has joined #crystal-lang
<FromGitter>
<girng> lol if u add a o after g it would be godotdesign
<FromGitter>
<girng> small world we live in, my friends.
<FromGitter>
<bararchy> yeha I was sure it was godot design my self
<FromGitter>
<girng> lol :)
ua has joined #crystal-lang
<FromGitter>
<girng> hmm, seems like json for large amount of data isn't really efficient because it sends redundant keys
<FromGitter>
<girng> i mean, it works nice for CMD name, and getting certain info. im just saying, i wonder if there is a solution to the redundant key problem. i know you mentioned msgpack, but unfortunately there is no module for that in godot for the client :(
<FromGitter>
<bararchy> you can do full binary protocol
<FromGitter>
<girng> let's say a player is request to view all the open games
<FromGitter>
<girng> look at all those redundant keys lol
<FromGitter>
<girng> that means the to_json method has to work harder right?
<FromGitter>
<girng> plz note: im not trying to put down json at all. i will in fact continue to use it, i LOVE IT for simple commands n whatnot. but for large information, i feel like it isn't right
<FromGitter>
<oprypin> we have discussed this already, nothing more to add
<FromGitter>
<girng> `key: the property name in the JSON document (as opposed to the property name in the Crystal code)` i use new key, for example `game_description` can just be `d`. with over 500 results, that's an insane difference.
<FromGitter>
<girng> Wow, cut that size a lot =]. this is why i need to read the docs more :D
<FromGitter>
<bararchy> can't you just Zip it before sneding ?
<FromGitter>
<girng> no idea, but json.mapping is prettty damn powerful, just gonna stick with this for now
olbat[m] has joined #crystal-lang
<FromGitter>
<drum445> If I wanted to use JSON Mapping for my classes but only supply some of the fields during init time, how would I best go about that?
<FromGitter>
<bararchy> you can add optional fields
<FromGitter>
<bararchy> ```test : String?```
<FromGitter>
<bararchy> etc..
<FromGitter>
<bararchy> so they can be initalized as nil
<FromGitter>
<bararchy> and you can add value later
<FromGitter>
<bararchy> or you could just save it as a big hash
<FromGitter>
<bararchy> and merge in new keys
<FromGitter>
<bararchy> and in the end do `.to_json`
Raimondii has joined #crystal-lang
<FromGitter>
<girng> So `location: {type: String, nilable: true},` is the same as `location : String?`
Raimondi has quit [Ping timeout: 264 seconds]
<FromGitter>
<bararchy> yeha
Raimondii is now known as Raimondi
<FromGitter>
<girng> lmao awesome
<FromGitter>
<drum445> oh nice, so i'd just pass a nil through to the initialize method?
<crystal-gh>
[crystal] MakeNowJust opened pull request #6013: Formatter: fix call args indent in case of backslash follows method name (master...fix/crystal-format/method-name-backslash-indent) https://git.io/vpCNQ
<FromGitter>
<drum445> I don't quite get that mate
<FromGitter>
<drum445> Mind putting it in a playground?
<FromGitter>
<drum445> something like that for the optional ones?
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
olbat[m] has joined #crystal-lang
tilpner has quit [Quit: :wq]
tilpner has joined #crystal-lang
braidn[m] has joined #crystal-lang
fifr[m] has joined #crystal-lang
byteflame has joined #crystal-lang
cptaffe has joined #crystal-lang
Renich has joined #crystal-lang
betofloresbaca[m has joined #crystal-lang
thunker[m] has joined #crystal-lang
kp666[m] has joined #crystal-lang
kixune[m] has joined #crystal-lang
jokke has quit [Quit: WeeChat 2.1]
<FromGitter>
<girng> is there a difference in performance of defining a Struct and then using it compared to doing like an inline NamedTuple? what's difference, since both are generated on the stack right?
DTZUZO has joined #crystal-lang
<oprypin>
no difference
<FromGitter>
<girng> personally, i like inline NamedTuples for some reason so ima just do what is more comfortable for me then
<FromGitter>
<girng> thank you
<crystal-gh>
[crystal] RX14 closed pull request #6004: Remove dependency on libxml from spec runner (master...jm/feature/spec-remove-libxml-dep) https://git.io/vpnPx
<FromGitter>
<girng> eh, i take that back i like structs better
<RX14>
you shouldn't like either of them better
<RX14>
they're different things for different cases
<RX14>
and you should use both
<FromGitter>
<straight-shoota> I believe it's a hopeless case, RX14 😆
<FromGitter>
<girng> rude
Nathanaelle has quit [Ping timeout: 255 seconds]
<FromGitter>
<bararchy> @girng he was joking, no need to take it personaly :)
<FromGitter>
<bararchy> anyway, what RX14 is saying is currect, each of them have it's own use, they both can be containers for data, but one is for X and the other for Y
<FromGitter>
<girng> which one falls under TEMPORARY DATA?
Nathanaelle has joined #crystal-lang
<RX14>
named tuples are more internal and ad-hoc
<RX14>
i'd not expose it in the API of a class
<RX14>
most of the time
<RX14>
record (struct) is a lot better for API work
<RX14>
tempoary data isn't very descriptive
<FromGitter>
<girng> for example: Client class: https://paste.ee/p/C8WZP, and Game class: https://paste.ee/p/u4MGD ⏎ ⏎ when a client (the player), creates a game. i have a `property games = {} of String => Game` in my masterserver class. so now, this hash is referencing the game name to the game class. that game class is now holding a hash of all players in that game. ⏎ ⏎ so, when a user requests game information for a
<FromGitter>
<girng> "and the player's in an array", i mean just an array of all the player's id's or names. not their entire property values from a `JSON.mapping`
<FromGitter>
<girng> i guess. maybe i should ask. is it possible to have different json.mappings? I could enable one just for when requesting game info, and use another when requesting more. that would make it easiest i think.
<FromGitter>
<drum445> Is it possible to only send certain fields in a JSON.mapping object when using to_json ?
<FromGitter>
<drum445> @bararchy would appreciate your help on this again
<FromGitter>
<j8r> Note that I'm working on getting CPU/memory for PID
<FromGitter>
<straight-shoota> @girng @drum445 You can't have different mappings in the same model and you can't customize the methods generated by that macro
<FromGitter>
<straight-shoota> @girng `{` after a method name is interpreted as block delimiter
<FromGitter>
<straight-shoota> not tuple literal
<FromGitter>
<straight-shoota> you'll need to wrap the argument in parenthesis
<FromGitter>
<girng> ok
<FromGitter>
<straight-shoota> @drum445 That looks utterly complicated
<FromGitter>
<straight-shoota> And unnecessarily makes a round trip of JSON serialization
<FromGitter>
<straight-shoota> what's wrong with the code I showed you?
<FromGitter>
<straight-shoota> @yxhuvud true, the argument is really compelling
<FromGitter>
<straight-shoota> the thing is, `go` and `spawn` are nice and simple, yet the implications can be complicated. And it's usually not really that often that you need to run a concurrent task
<FromGitter>
<drum445> The code you sent was nice, but it would mean having to add a line of code for each json key
<FromGitter>
<drum445> so if i had an object with 20 JSON keys it would be 20 lines long
<FromGitter>
<straight-shoota> then put it in a macro
<FromGitter>
<straight-shoota> which receives the named tuple literal from `JSON.mapping` and expands to calling `JSON.mapping` with that argument and generate `to_json` directly
<FromGitter>
<straight-shoota> where the `id` is stripped off
<FromGitter>
<drum445> Mate, I'm sorry but could you playground that. It's a bit over my head
<RX14>
you can make description and name immutable
<RX14>
and just initialize it directory in the constructor
tilpner has joined #crystal-lang
<FromGitter>
<girng> interesting
<RX14>
@girng with your code you can do gameInfo.new and then never initialize the information
<RX14>
it's easy to make mistakes
<FromGitter>
<girng> but i mean what do you mean default value, there will always be a value there when it's called? or is it because of the property macro,sorry bit confused
<RX14>
in my code that's impossible
<FromGitter>
<girng> bcz i fill in the info
<FromGitter>
<girng> but i mean your code looks way cleaner...
<RX14>
but it's much better to fill in the information by passing it to .new
<FromGitter>
<girng> Ohh as parameter
<RX14>
instead of setting it manually after
<RX14>
it's possible to forget to initialize it
<FromGitter>
<girng> oh i see
<RX14>
the default values i'm talking about are `""`
<RX14>
my code gets rid of them
<RX14>
it forces you to initialize the GameInfo
faustinoaq has quit [Quit: IRC client terminated!]
<RX14>
with the required info
<FromGitter>
<girng> yeah, and if i forgot about them, unecessary stuff being generated
<FromGitter>
<girng> =BAD, correct?
<RX14>
if you ever edit GameInfo to add a new variable, then you'd edit the constrictor
<RX14>
and if you forgot to initialize it somewhere, you'd fail to compile
<RX14>
instead of compile fine and return bad data
<FromGitter>
<girng> then the player get's DC'd and reports bug on forum = waste time :D
<RX14>
sure
<FromGitter>
<girng> lol gotcha.
<FromGitter>
<girng> i get it
<FromGitter>
<girng> well, kinda want to clean up my Client class now, but might have a bit too much parameters lol
<RX14>
crystal gives you the tools to write code which is hard to misuse, but it doesn't force you to write code that is hard to misuse
<RX14>
getting into the habit of thinking about how to break your own code and how to prevent that is a good skill
<RX14>
@girng you can always use named paramters
<RX14>
.new(
<RX14>
foo: bar,
<RX14>
baz: bing
<RX14>
)
early` has quit [Quit: Leaving]
<RX14>
etc.
<RX14>
but with the right indents
<FromGitter>
<girng> oh lord
<FromGitter>
<girng> that would be nice
<RX14>
it's the same code length :P
<RX14>
well, you add 1 more line for ) but that's unimportant
<FromGitter>
<girng> bcz in my client.new now it's kinda mess. kinda the same thing in GameInfo i showed u lol
<RX14>
yeah
<FromGitter>
<girng> and it gets worse when they hit handle_authentication, when i assign the values from db :D
<FromGitter>
<girng> but sheis running fine, but im not in production thx gosh :D
<RX14>
well, you'll write bad code, and it'll go wrong, and that's fine
<RX14>
you'll look back at your code in a few years and think "that's terrible"
<RX14>
but that's fine, because it means you've learned
<FromGitter>
<bew> And yes, you need to update your system, this is how arch works, this is a rolling release distro, the packages are built against the latest packages of everything, and are meant to be run the same way
<FromGitter>
<DRVTiny> How to do conditional compilation in macroses? ⏎ What is the syntax of {% if ? ⏎ How can i do {% if flag == 1 do %} macro_code {% end %}
<FromGitter>
<DRVTiny> Macroses - its all about conditional compilation :)
<FromGitter>
<DRVTiny> It is strange, but this VERY basic question was not discussed in docs at all!
<FromGitter>
<bew> Hum.. You can try to upgrade llvm only, but I can't assure you that it won't break your arch (but it's very unlikely ut woukd though) @xmonader
<FromGitter>
<bew> (I like your username :) )
<FromGitter>
<xmonader> @bew Already trying to do llvm update or maybe i fallback to a crystal docker
<FromGitter>
<Givralix> hi! I have another question about C bindings
<FromGitter>
<DRVTiny> @r00ster91 Thank you! That works! :)
<FromGitter>
<Givralix> there's a point where I need to cast a struct pointer into another struct and that mostly works fine except for one value which stays the same as one of the values from the original struct
<FromGitter>
<Givralix> I've tried making a function in C which does the cast and prints that value and in there it's fine but as soon as it's in Crystal, it changes
<FromGitter>
<Givralix> does anyone have a clue ? :o
<oprypin>
Givralix, i am intrigued, but would need more details (mainly code)
<FromGitter>
<Givralix> as in enough code to run it or just the part where it goes wrong?
<oprypin>
i dunno
<FromGitter>
<Givralix> hold on
<FromGitter>
<j8r> @bararchy I'm very honored for the mention, thank you! :-)
<FromGitter>
<Givralix> (LibXCB::KeyPress is also 2, and the problem also happens with key release events, in which case it prints 3, LibXCB::KeyRelease's value)
<oprypin>
Givralix, I see. these event thingies can be hard to understand in their C code. could you show the C code though?
<FromGitter>
<j8r> How can I have an infinite iterator? I would like to have a `def` that can take an argument to specify how number of times to iterate, or infinite times
<FromGitter>
<j8r> the iterator must be inside because there are variables
<FromGitter>
<bew> You can make your own iterator
<FromGitter>
<bew> Checkout the api doc of `Iterator`
<FromGitter>
<j8r> Thanks, already checked but can't find a way to make one (except having a BIIIGGG number) :/
<FromGitter>
<j8r> *infinite iterator
<FromGitter>
<j8r> I will find another way, `while true` would be fine
<FromGitter>
<jwoertink> wouldn't using "loop" work?
<FromGitter>
<j8r> yes, but if we want to have only x time?
<FromGitter>
<jwoertink> with `break if x == 3`
<FromGitter>
<jwoertink> or I guess
<FromGitter>
<jwoertink> `break if needs_to_stop`
<FromGitter>
<jwoertink> where `needs_to_stop` is like x == 3 || false
<FromGitter>
<j8r> I use a `i += 1`
<FromGitter>
<jwoertink> something like that
<FromGitter>
<jwoertink> maybe a method where you either pass in the stop number or nil. If it's nil, then keep the loop going, if it's not, then += 1 until it hits that number
<FromGitter>
<jwoertink> or just do `Float32::INIFINITY.times do` lol. I'm sure that wouldn't work, but would be funny
<FromGitter>
<j8r> already tired haha :-P
<FromGitter>
<bew> What's your usecase? How do you want to use it?
<FromGitter>
<j8r> For the shard Hardware, in the module`Hardware::CPU`
<FromGitter>
<j8r> I think I would of for a `loop; yield cpu; end`
<FromGitter>
<j8r> when the method will called, there will have an infinite loop. The user can implement its break
<FromGitter>
<j8r> I create the PR, you will see the use case :-)
sagax has quit [Ping timeout: 240 seconds]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]