Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 616 617 [618] 619 620 ... 796

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

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9255 on: March 21, 2016, 01:49:52 am »

Facebook does have an API, but it's vile.

The API is mostly for game developers that want their apps to be able to make shareable Facebook posts, from what I've seen. And the documentation comes in fifty pieces across as many websites and it's totally unclear what is part of what. I have neither time nor inclination to sort out that incomprehensible mess, on top of learning how to use POST and REST and whatever else I'd need.

I was thinking that I wanted to have a background script that would analyze "trending" stories on my news sidebar, maybe over a month, maybe over a year, and see what subjects keep recurring. I feel like the overwhelming majority involve suicides, murders and injuries, and maybe if I write a script to state the obvious then I'll go viral and get a job at Google or something.

Even if there is an official way to do that, making a kludge with Selenium and Python is faster and easier on my sanity.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9256 on: March 21, 2016, 04:47:44 am »

Okay, I understand what recursive methods are, and how they can be useful, but how can I make an iterative method into a recursive one? This new kind of logic is defeating me at the moment.

Here's an example.
Code: [Select]
public class printArray
{
// initializes values
public static void main ( String args[] )
{
int array[] = { 81, 22, 18, 34, 44, 21, 94 };

for ( int count = 0; count <= 6; count++ )
System.out.print( array[count] + " " );
}
}

This will output the contents of the array with spaces between them. How can I make that recursive?
Generally you turn all of the iteration variables into parameters for the recursive function and in the recursive call you pass the values for the next step as arguments.
Logged
Taste my Paci-Fist

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9257 on: March 21, 2016, 04:53:34 am »

Hey I just thought I'd mention I'm looking for some pixel/3D artists to work on a game dev project, and I'm offering some gifts/freebies to try and make it worth people's time (though I am an impoverished student myself). If anyone is interested, PM me or I have a link my .sig with a few details, though I'm going to update that with some screenshot and samples of what I already have working later.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9258 on: March 21, 2016, 08:46:28 pm »

I just realized that I am really really sick of the tendency to name everything a somethingController. I realize this because I named my health script (read: a single integer and two functions) a "healthController".
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9259 on: March 21, 2016, 11:09:59 pm »

Depending on how it's used, that sounds like it could almost be a HealthComponent instead or something.  But then you're right back to square one with naming tons of things FooSomething.  If you have 30 Component classes inheriting from a base Component class, anyway.

In my experience though, things called controllers are usually like things called managers.  Occasionally that's a good and meaningful name for things, but all too often I've seen it used to just refer to a collection of some kind and methods for adding or removing things from it.  Very often they're intended to be singletons too, whether they are literally or not.

I've toyed with the idea of using C++ namespaces and plain data and functions instead of a class which is intended to have only a single instance and does nothing more.  It's usually a glorified global anyway.

But then I start thinking about how that works in practice and it just feels wrong.  I always second guess if it would ever need to be subclassed or possibly instanced several times... and even for things that feel like they'd never have multiple instances (FileManager, InputManager, etc) I can think of odd cases where you might...
Logged
Through pain, I find wisdom.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9260 on: March 21, 2016, 11:45:41 pm »

I mostly use singletons when I need a list of all the _____ in a scene, for pathfinding/targeting purposes. So instead of every object having a function to find an object that fits the appropriate criteria (a gameObject with an enemyAI component), it can just pick randomly from a list that was compiled when the simulation began and is only updated as needed.

But then because of the way Unity (and most game engines I've used) are structured, you can't just "have" variables that are part of the top level of the program; every variable must be on a component attached to an object that exists in the scene. Thus, singleton.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Moghjubar

  • Bay Watcher
  • Science gets you to space.
    • View Profile
    • Demon Legend
Re: if self.isCoder(): post() #Programming Thread
« Reply #9261 on: March 22, 2016, 12:33:31 am »

I just realized that I am really really sick of the tendency to name everything a somethingController. I realize this because I named my health script (read: a single integer and two functions) a "healthController".

I need a mylifeController.  Trying to push myself to program/design and get a full playable level in my platform/shooter thingy by next month, been too distracted by basically everything.
Logged
Steam ID
Making things in Unity
Current Project: Demon Legend
Also working on THIS! Farworld Pioneers
Mastodon

MoonyTheHuman

  • Bay Watcher
  • I think the DEC VAX hates me.
    • View Profile
    • hellomouse
Re: if self.isCoder(): post() #Programming Thread
« Reply #9262 on: March 22, 2016, 06:45:00 pm »

Well i got a worse project, its called a dwarf fortress like simulation as a open source project >_>
Code: [Select]
struct emotident { // emotion defines
int stressmod,
int numid,
string stringidlower,
string stringidupper};
emotident emotidentasm(int o1, int o2, string o3) { //Im lazy, so im gonna shrink it down to one line! ('=
    emotident temp;
    temp.stressmod = o1;
    temp.numid = o2;
    temp.stringidlower = o3;
    temp.stringidupper
    return temp
}
emotident mpain = emotidentasm(-1,0,"minor pain","Minor pain");
emotident happyness = emotidentasm(+1,1,"happyness","Happyness");
emotident anger = emotidentasm(-2,2,"anger","Anger");
emotident sadness = emotidentasm(-2,2,"sadness","Sadness");
emotident disgust = emotidentasm(-4,2,"disgust","Disgust");
is this code valid? just checking

MoonyTheHuman

  • Bay Watcher
  • I think the DEC VAX hates me.
    • View Profile
    • hellomouse
Re: if self.isCoder(): post() #Programming Thread
« Reply #9263 on: March 22, 2016, 06:48:30 pm »

nvm, tryed to compile, compiler gave a shit on all the errors
revised code that actually works:
Spoiler (click to show/hide)

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9264 on: March 22, 2016, 08:22:11 pm »

My Selenium experiments create exactly one runaway PhantomJS process. Any subsequent runs will close the process they create, so there will only ever be one unused process, but they'll still give the same error upon exit or calling driver.quit(), close() or dispose():

Code: [Select]
Traceback (most recent call last):
  File "C:\Users\-\Documents\_Programming\Python\bay12cli\bay12cli.py", line 22, in <module>
    driver.quit()
  File "C:\Python34\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 74, in quit
    self.service.stop()
  File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 127, in stop
    self.send_remote_shutdown_command()
  File "C:\Python34\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 68, in send_remote_shutdown_command
    os.remove(self._cookie_temp_file)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\ALEXAS~1\\AppData\\Local\\Temp\\tmpxjlxds11'

Seems like a permission error, right? I've tried running three IDEs as admin. I've tried running the script from the command line as admin. I've tried setting PhantomJS to always run as admin. No dice. I have no idea what "other process" it could be referring to, since it happens when there's only one PhantomJS running, and PhantomJS itself created that tempfile.

Here's the code. I turned it into a command-line Bay12 viewer because I thought some people might find that silly and enjoyable, but I refuse to keep going until I fix this PhantomJS issue.

Code: [Select]
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.PhantomJS("C:/Users/-/Desktop/phantomjs-2.1.1-windows/bin/phantomjs.exe", port=9001)


def mainpage():
    driver.get("http://www.bay12forums.com/smf/index.php")
    print("Got page")

    links = driver.find_elements_by_xpath("//a[@name[contains(., 'b')]]")
    print("Got links")
    for i in range(0, len(links)):
        print(str(i) + "). " + links[i].text)

    print("a = next page, b = previous page, # = select subforum")
    inp = input(">")

mainpage()
driver.save_screenshot("screen.png")
print("Saved screenshot")
driver.quit()
« Last Edit: March 22, 2016, 08:34:56 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.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9265 on: March 22, 2016, 09:46:27 pm »

disregard, solved the problem.
« Last Edit: March 22, 2016, 09:52:54 pm by Spehss _ »
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9266 on: March 22, 2016, 09:53:16 pm »

Look into the c-language sprintf family of functions. They work with printf format strings, but output to a char * buffer. Easy to convert to a string from that. printf, sprintf and fprintf (for file output) are easier to work with than the c++ style formatters.

Another method uses the c++ stringstream class. They work like cout, but store the output into a string buffer.
« Last Edit: March 23, 2016, 05:10:11 am by Reelya »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9267 on: March 23, 2016, 05:09:08 am »

disregard, solved the problem.
How'd you solve it?  Edify us!
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9268 on: March 23, 2016, 05:11:20 am »

Spoiler: Obligatory XKCD (click to show/hide)
« Last Edit: March 23, 2016, 05:16:21 am 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.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9269 on: March 23, 2016, 10:39:35 am »

How'd you solve it?  Edify us!
I changed a couple char variables I was using from 1 char per variable to arrays of 2 chars. Surprisingly simple. itoa stored each digit of the int in an array slot automatically.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.
Pages: 1 ... 616 617 [618] 619 620 ... 796