Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 652 653 [654] 655 656 ... 796

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

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9795 on: July 05, 2016, 03:02:06 pm »

I can't do trigonometry either. I used to have a python module that'd do everything wonderfully, but it has since vanished and I can't find one that's quite the same.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9796 on: July 05, 2016, 05:28:17 pm »

I use Math.Atan2.

the inverse tangent, yes

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9797 on: July 08, 2016, 03:14:42 am »

I'm writing a website in HTML. I want to align these input fields with the red line I've drawn in the middle of the image:
Spoiler (click to show/hide)

What's the best way to do that without manually going through and offsetting them one at a time? Here is my code (first is HTML and the second is the CSS):
Spoiler (click to show/hide)
Logged

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9798 on: July 08, 2016, 03:19:24 am »

I have this website bookmarked: http://howtocenterincss.com/
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9799 on: July 08, 2016, 04:16:07 am »

I appreciate UI designers and programmers so much after having to do GUI shit myself in a variety of contexts. Unity does almost everything I can think of to make it easy for idiots like me and I can still barely ever achieve the result I want.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9800 on: July 08, 2016, 04:25:09 am »

I have this website bookmarked: http://howtocenterincss.com/

I settled on this
position relative/absolute
top/left 50%
translatex/y -50%

that works in most cases, it's responsive on parent and children, handles well a children larger than the parent etc.
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9801 on: July 08, 2016, 12:23:08 pm »

Nevermind. I just put the input boxes on the opposite side.
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9802 on: July 09, 2016, 02:20:18 am »

Can somebody look at the code that I have to show inventories in a Unity game? I can't shake the feeling that I'm doing this in a way that's going to screw me somewhere down the line.


Spoiler: character_Inventory.cs (click to show/hide)
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 #9803 on: July 09, 2016, 08:02:14 pm »

You can streamline the nextInventory using modulo

public void nextInventory()
{
    partyInventoryIndex = (partyInventoryIndex + 1) % party.characters.Count;
}

This adds 1 to partyInventoryIndex, but goes back to zero if it hits party.characters.Count. This assumes the first character is character #zero however. To get modulo to work for the prevInventory you need to be trickier, since modulo doesn't wrap a negative properly.

public void prevInventory()
{
    partyInventoryIndex = (partyInventoryIndex + party.characters.Count - 1) % party.characters.Count;
}

This takes advantage of the fact that partyInventoryIndex + party.characters.Count modulos to the same as partyInventoryIndex, so subtracting 1 from that effectively lowers it by one while allowing wrap-around by party.characters.Count.

What I would suggest in general however is to refactor showPlayerInventory and showOtherInventory so that they use the same codebase (as much as possible). Look for sections of code which are the same or very similar in structure - they don't have to be exactly the same. You can then make a function which can fill in for either section of code, and parameterize any small differences that exist.
« Last Edit: July 09, 2016, 08:19:27 pm by Reelya »
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9804 on: July 09, 2016, 08:20:29 pm »

I just wanted to do a simple test to make sure the submit button on the page was working. The dropdown menus are set to the default values, and when I click, the page just loads forever. What's going on here?

calculator.html
calculation.js
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9805 on: July 09, 2016, 09:11:44 pm »

I just wanted to do a simple test to make sure the submit button on the page was working. The dropdown menus are set to the default values, and when I click, the page just loads forever. What's going on here?

calculator.html
calculation.js

The page isn't loading forever - the input is calling a different write function and blanking the page (possibly document.write but I don't particularly feel like reading up on that on my day off).

If you call your function anything else, it works.
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9806 on: July 09, 2016, 09:57:26 pm »

Wow I feel dumb! Thank you.
Logged

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9807 on: July 09, 2016, 11:17:10 pm »

Hey, C++ noob here. Can someone help me with this?

I'm programming a roguelike, and I want my current level (containing tiles, monsters, items, etc) to be more accessible to other functions. Right now, it's a LevelMap object tucked inside a World object. If I want to access something in a level, I need to type world.levels[world.currentlevel].foobar which feels excessive. After looking at other roguelikes, it seems like they have a single global level. It's loaded in and out of memory and can be accessed with simply level.foobar. Cool. So I tried this:

Code: (levelmap.h) [Select]
class LevelMap
{
// LevelMap definitions
}

extern LevelMap currentlevel;

Code: (levelmap.cpp) [Select]

LevelMap currentlevel;

// LevelMap functions

That compiles without any warnings or errors...but it immediately crashes and gives me a segmentation fault before the program even reaches main(). What gives? Can anyone tell me why this approach would not work for my LevelMap?

EDIT:

I think I found the culprit:

Code: [Select]
Tile(int tileID = 0, int xpos = 0, int ypos = 0)
{
name = TileIDList[tileID].name;
// Setting a bunch of other tile variables
}
   
When constructing the tiles in my map, there's a segmentation fault when setting the name. TileIDList[tileID].name is a const char* array stored in a struct. If I comment out that line (so all tiles are nameless) the program compiles just fine. I'm dumbfounded, because I'm constructing my Monsters in the same exact way with MonsterIDList[monsterID].name. I hate C++ strings.
« Last Edit: July 09, 2016, 11:44:04 pm by DragonDePlatino »
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9808 on: July 10, 2016, 12:27:40 am »

Code: (levelmap.h) [Select]
class LevelMap
{
// LevelMap definitions
}

extern LevelMap currentlevel;
Shouldn't there be a semi-colon after the end of your class definition?
Code: [Select]
class LevelMap
{
// LevelMap definitions
};

extern LevelMap currentlevel;

I'm not entirely sure why it has to be there. I think maybe that separates it from a function that returns "class", but I'm not sure that's even possible.

(Maybe you just omitted it in the post, because I don't think it would compile without errors otherwise.)
« Last Edit: July 10, 2016, 12:33:00 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9809 on: July 10, 2016, 12:31:30 am »

The issue is that you can't control the order that static global variables call their constructors, so by moving something to global scope you're moving it's constructor to be called earlier. Other objects it relied on may not have had their constructors called at that point in time.  Consider moving the entire contents of the LevelMap constructor into some type of Init function, which you can call when you want to.

Quote
I'm not entirely sure why it has to be there, but I think maybe that separates it from a function that returns a class.

The semi-colon has to be there because you can declare objects of a class when you declare the class:

class MyClass
{
} myClassObject1, myClassObject2;

So, without the semi-colon it's not a complete statement.
Pages: 1 ... 652 653 [654] 655 656 ... 796