Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 766 767 [768] 769 770 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 804327 times)

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #11505 on: September 18, 2019, 07:38:55 pm »

It worked! Hell yeah, as soon as I could actually get the output printing I zeroed in on the problem, my lookup() was fine, I was missing a break statement in my switch. Making smooth progress, thanks so much y'all!

Bonus! Here's an explanation of the "cout literal mixing" error from my friend
Code: [Select]
5:26 PM] MyPal: The precedence of the + operator in  C++ is higher than the << operator, so when you do
cout << someInt + "some string"
you're actually doing
cout << (someInt + "some string")
[5:28 PM] MyPal: But! Wanna know why the compiler doesn't complain (and why it was eating some characters)?
[5:28 PM] MyPal: (also yeah don't worry no judgement, I've seen java and the implicit type stuff looks like a nightmare to me XD)
[5:33 PM] MyPal: A string literal in C++ is actually just an array of characters, and the type of an array of characters often just decays into a pointer to first element (in this case, a const char* pointing to the first 's' character in the string literal)
[5:33 PM] MyPal: And when you add an integer to a pointer you're just moving forward in the array.
5:37 PM] MyPal: yeah, it's trying to add two pointers and that's technically an error XD You unfortunately can't concatenate two string literals together in C++.

So the reason the compiler was eating characters is because I was incrementing the pointer past them by adding an integer to the pointer.
What I should have been doing was: cout << "some string" << integer1;
« Last Edit: September 18, 2019, 07:40:35 pm by Parsely »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11506 on: September 19, 2019, 03:02:41 am »

Ah, I'm embarrassed that I didn't pick that up myself, I had a quick look over the code, and missed the fact. I must be doing too much C# and JavaScript these days, in which you do concat strings like that.

You can concat std::strings using the "+" operator normally, and you can also write your own "+" operators that work with user-defined types in C++, but you can't create new operators to overload the behavior of primitive types. Those work the way they do to ensure backwards compatibility with C code.

Also be aware that there can be a performance difference between "cout << string1 + string2" vs "cout << string1 << string2. The first version technically makes a new string, copying the entire contents of both existing strings to it, then streams the results of that copy operation, while the second version just streams the contents of the first string followed by the contents of the second string.
« Last Edit: September 19, 2019, 03:04:44 am by Reelya »
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #11507 on: September 19, 2019, 07:50:23 am »

Ah, I'm embarrassed that I didn't pick that up myself, I had a quick look over the code, and missed the fact. I must be doing too much C# and JavaScript these days, in which you do concat strings like that.
Yuuup, that's exactly why I missed it too :P Thanks for taking a look though
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11508 on: September 23, 2019, 09:24:36 am »

First recorded instance of the Ballmer Peak?

Quote
He too remembered being confused by the table at the time. “I couldn’t unscramble it,” he told the researchers. And he claimed it had been the work of a programmer who developed it while not entirely sober: “He told me it came upon him when he was drunk and whacked out of his brain.”
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11509 on: September 29, 2019, 10:05:16 pm »

This stupid RPG I'm making has made me truly realize how much I hate coding menus.

It all started when I decided that the interface should mimic that of a classic Final Fantasy game. It's a hell of a time making Unity's default UI work consistently and not look like ass, and the overwhelming majority of RPGs are nothing but menus.

All bets were off when I decided to deliberately exclude mouse support; it's something I did to mimic the digital feeling of games like Wizardry, Might & Magic, and other games that came out before the mouse was widespread. Since then, it's been an uphill battle making everything look and feel consistent and not like an amateur hack job in an engine that desperately wishes I were making a different game.

My favorite workaround is a script that adds a 0.1 second delay after building a list. Unity's buttons won't highlight if you hover over them before they're ready, so the keyboard menu script delays before selecting the first button in that list. Programming! :'(

If I ever say that I'm making anything vaguely like an RPG again, remind me of this post.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11510 on: September 30, 2019, 05:48:57 am »

The trick with Unity is to know when not to build things with Unity components. Your UI elements don't actually have to have Unity UI element code in them. They don't even need to be objects, they just need to be drawn on the screen.

For a good "menu" system in Unity, I'd actually suggest avoiding coupling it too tightly with Unity's code. i.e. don't directly wire functions into buttons using the Unity UI. Instead, design your own "command system", which takes commands, then runs them. Each menu item then becomes a data structure that consists of a label, and a command (possibly with some other types of items such as sliders and toggles as allowed menu items).

Then, dynamically generate any needed menus, based on the labels / command data. This would be much more manageable than trying to wire up menus by hand, and it keeps functionality separate from design.
« Last Edit: September 30, 2019, 06:06:58 am by Reelya »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11511 on: September 30, 2019, 11:52:49 am »

More generally, many game engine features should really not ever be used outside of mockups or prototypes.
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11512 on: September 30, 2019, 01:40:03 pm »

More generally, many game engine features should really not ever be used outside of mockups or prototypes.

Plenty of successful well-made games are made using completely stock engines. Particularly, small indie projects.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11513 on: September 30, 2019, 02:08:33 pm »

The question isn't what they used for their first successful project. The question is what they used for their second.

According to this Wikipedia article, games made in recent versions of Unreal include Kingdom Hearts III, the upcoming Final Fantasy VII remake, Fortnite, Mass Effect 1-3, and most of the Gears of War franchise. Unity games include Gwent (the card game from Witcher,) Hearthstone, Pokemon Go, Super Mario Run, ARMA Tactics, Mario Kart Tour, and Honkai Impact 3rd. All from large, or relatively-large companies with previous installments on their belt that have more than enough money and previous tech to rely upon.

TL;DR I simply refute the premise that "using an engine" is always an inferior choice. Especially when the alternative is my amateur, unskilled, unpaid self reinventing the wheel from the ground up when there's just no reason to, even if there's parts of the current wheel that I don't really care for.
« Last Edit: September 30, 2019, 02:10:05 pm by itisnotlogical »
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11514 on: September 30, 2019, 08:08:16 pm »

Yeah, nobody even alluded to "roll your own engine" here. What was said / implied is don't only use the stock components. A good Unreal game has a ton of custom C++ behind it, those people aren't just wiring up prefabs from the noobie toolbox they give you.

That's the problem I alluded to. A lot of people just wire up the built-in components, because it's faster, then they wonder why their game is doing weird shit and they can't customize things to look and act like they want later.

The thing is: use Unity as a graphics engine, but don't literally build everything inside the game out of unity's GameObjects in the inspector. If you do that, you end up with a huge unwieldy monolith, a huge nested tree of GameObjects of various types, that's extremely hard to modify, and basically impossible to debug if things don't do what you want.

EDIT: For a more concrete example, consider something like building DF in Unity. If you make every creature a Unity "GameObject" with attached scripts, sprites, and animation frames, then each and every creature is running an update loop every frame. Even if they're not doing anything, even if they're not on the screen. instead, you could just model all the creatures as values in an array, and you only render what's necessary when needed. You lose the entire bulky overhead of inheriting from Unity's do-everything "GameObject" class for hundreds of your game-creatures.
« Last Edit: September 30, 2019, 08:22:16 pm by Reelya »
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #11515 on: October 17, 2019, 02:46:26 pm »

I'm using a multimap in C++ but I only just found out late into this project that it doesn't preserve the order of insertion and that's important. It works as intended when there are only unique values but it looks like it rearranges the values when I insert a duplicate key and I don't want it to do that. I don't think I can control this behavior, so it looks like I'm going to have refactor all my code I guess
Logged

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11516 on: October 17, 2019, 02:59:18 pm »

you can add a sortable prefix to the key, depending on how the key is generated/stored
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #11517 on: October 17, 2019, 03:21:12 pm »

Oh? I think I read something briefly about that but I found another solution. I was actually able to seamlessly swap it with a list of pairs since I was using iterators to index my data structures, all I had to do was change some types and it just worked as intended. I wasn't expecting to solve it this quick and I'm shocked that went so smoothly.
Logged

bloop_bleep

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11518 on: October 17, 2019, 04:22:00 pm »

Yeah that sounds similar to what LoS was suggesting, with the second element of the pair being the key. Lexicographical comparison makes it work similar to a multimap.
Logged
Quote from: KittyTac
The closest thing Bay12 has to a flamewar is an argument over philosophy that slowly transitioned to an argument about quantum mechanics.
Quote from: thefriendlyhacker
The trick is to only make predictions semi-seriously.  That way, I don't have a 98% failure rate. I have a 98% sarcasm rate.

McTraveller

  • Bay Watcher
  • This text isn't very personal.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11519 on: October 31, 2019, 02:44:46 pm »

This is why open source has a bad reputation:

Quote
cc1.exe - System Error

The code execution cannot proceed because libwinpthread-1.dll was not found. Reinstalling the program may fix this problem.

So much dependency hell.... and searching for the cause is just full of "why would you ever try to do the thing you are doing? Just do it this other way..." with incomplete instructions.

 >:(


Logged
Pages: 1 ... 766 767 [768] 769 770 ... 795