Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 731 732 [733] 734 735 ... 795

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

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10980 on: July 05, 2018, 07:07:05 pm »

Can you also share how you're calling the match method?

Vaguely related, the penultimate line won't work. "die()" expects an argument.
Logged

Eschar

  • Bay Watcher
  • hello
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10981 on: July 05, 2018, 08:50:49 pm »

Hmm. I copied just the class definition into a new IDLE shell and it worked fine and is continuing to do so. Thanks for noticing the die() problem, though; I will fix that immediately.
Logged

Kagus

  • Bay Watcher
  • Olive oil. Don't you?
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10982 on: July 18, 2018, 01:20:12 pm »

Code: [Select]
for(var/i = 0; i < 2; ++i)
Out of Context Code Quotes... I feel like that is or should be a thing.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10983 on: July 18, 2018, 01:53:14 pm »

What language is that?  Looks like JavaScript, but it's not valid since it thinks var/i is trying to form a regular expression literal.  Unless that's the point of the post.  :)

I should look and see if I can find any amusing snippets from code here at work.  I have some funny comments at least.
Logged
Through pain, I find wisdom.

Kagus

  • Bay Watcher
  • Olive oil. Don't you?
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10984 on: July 18, 2018, 02:35:34 pm »

That's DreamMaker again. Yet more of SS13's delightful coding (although that's actually taken from a Github PR where someone put the poor thing out of its misery). Open-source programming is great, huh?

Normally it gets used more like:
Code: [Select]
for(var/i in 1 to 3) often to just fill a loot chest or something with a random amount (1 to 3) of whatever item it's handling.


The other example is... Well, I'm sure it's a creative solution. Not a good solution, but creative.

I'm not sure how it worked, actually, because the items it was handling did actually appear ingame. So, it compiled and ran successfully. Somehow.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10985 on: July 18, 2018, 02:44:15 pm »

I'm getting flash backs to a legacy application translation I did at my last job. Nested for loops that heavily featured GOTOs to move around within the loops.

I spent way too much time on it. Found out I could trash all of it because, without fail, it always executed exactly twice.

I do not miss vbscript.
Logged

WealthyRadish

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10986 on: July 18, 2018, 02:49:08 pm »

That's DreamMaker again. Yet more of SS13's delightful coding (although that's actually taken from a Github PR where someone put the poor thing out of its misery). Open-source programming is great, huh?

Normally it gets used more like:
Code: [Select]
for(var/i in 1 to 3) often to just fill a loot chest or something with a random amount (1 to 3) of whatever item it's handling.


The other example is... Well, I'm sure it's a creative solution. Not a good solution, but creative.

I'm not sure how it worked, actually, because the items it was handling did actually appear ingame. So, it compiled and ran successfully. Somehow.

The example you showed mirrored the syntax of C++ and some other languages, which would usually be "for (int i = 0; i < 2; i++)". It's not unusual at all, in fact I'd say it's more common in programming (even when the language supports something else).

Edit: Oh, is it not a loop?
« Last Edit: July 18, 2018, 02:53:03 pm by UrbanGiraffe »
Logged

Kagus

  • Bay Watcher
  • Olive oil. Don't you?
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10987 on: July 18, 2018, 03:26:12 pm »

That's DreamMaker again. Yet more of SS13's delightful coding (although that's actually taken from a Github PR where someone put the poor thing out of its misery). Open-source programming is great, huh?

Normally it gets used more like:
Code: [Select]
for(var/i in 1 to 3) often to just fill a loot chest or something with a random amount (1 to 3) of whatever item it's handling.


The other example is... Well, I'm sure it's a creative solution. Not a good solution, but creative.

I'm not sure how it worked, actually, because the items it was handling did actually appear ingame. So, it compiled and ran successfully. Somehow.

The example you showed mirrored the syntax of C++ and some other languages, which would usually be "for (int i = 0; i < 2; i++)". It's not unusual at all, in fact I'd say it's more common in programming (even when the language supports something else).

Edit: Oh, is it not a loop?

Nope, it's supposed to initialize once in order to populate a list with objects, then it's done. Or at least, then it's supposed to be done.

bloop_bleep

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10988 on: July 22, 2018, 09:31:16 pm »

What you're showing there is almost definitely a loop, and as UG said, the most common syntax for a loop in programming languages. A loop doesn't mean a piece of code that keeps repeating forever; that's an infinite loop. A loop is just a code construct that repeats some instructions for some number of times. What's that example is doing is repeating the code for inserting <blank item> into loot chest 3 times over. Also, the other example you gave, namely

Code: [Select]
for(var/i in 1 to 3)
most likely does NOT populate the loot chest with a random number from 1 to 3 items, but rather exactly 3, just as the first example does. This is because what it does is it first runs the code in the loop with i set to 1, then i set to 2, then i set to 3 -- basically looping the code for all values of i from 1 to 3, hence the syntax. Even if the value of i isn't actually used in the code that's being looped, this still is a convenient way to loop through exactly 3 times, and indeed looks nicer than the first example.

Not at all trying to sound patronizing, but just some friendly advice, maybe you should look up an online manual or something on the syntax of the language you're using? It might be really helpful.
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.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10989 on: July 22, 2018, 09:43:23 pm »

For variables or functions dream maker has scope indicated with / like a Unix file path. so var/i just means the same as "var i" would in JavaScript. var is the enclosing scope, i is the variable.

Same as what bloop_bleep said. it's a for loop that runs 3 times. That's just what for loops do.

People complain about "weird" stuff that Dream Maker does, almost all of which is perfectly normal stuff that other languages already do. For example, when someone was freaking out because BYOND allows you to use a boolean value as a numeric. Guess what? c and c++ also allow that, and professional coders exploit it to write much more confusing code than that BYOND stuff. Maybe the reason people complain about such everyday stuff in BYOND is because most BYOND coders haven't had to deal with c/c++ and other languages much.
« Last Edit: July 22, 2018, 09:52:51 pm by Reelya »
Logged

Kagus

  • Bay Watcher
  • Olive oil. Don't you?
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10990 on: July 23, 2018, 05:14:56 am »

What you're showing there is almost definitely a loop, and as UG said, the most common syntax for a loop in programming languages.
This was more a communication error. I interpreted the question as meaning "is this function called multiple times" rather than "does this function itself run multiple times when doing its job". This is probably mostly due to my just not commonly thinking of "run X once for each number between 1 and 3" as a loop, as I'm not used to thinking in those terms.

Also, the other example you gave, namely

Code: [Select]
for(var/i in 1 to 3)
most likely does NOT populate the loot chest with a random number from 1 to 3 items, but rather exactly 3, just as the first example does.
Now, see, I knew this is how it worked. I'd seen it work as such.

I remembered it as a "pick a value between 1 and 3" because I'm an airhead. I don't have a better explanation for that.

Not at all trying to sound patronizing, but just some friendly advice, maybe you should look up an online manual or something on the syntax of the language you're using? It might be really helpful.
I've tried looking up a few different functions in the online documentation, with extremely limited success. This is most likely due to my just not knowing how to search for something, but I seem to recall at least part of the documentation for mathematics just saying "these do what you'd expect", when I was specifically looking to see if the slash in "if((x_define / y_define) >= defined_value)" could mean anything other than just dividing the number, because to my mind dividing the number didn't make any sense.

Not that it'd make much difference if I could read the thing anyways, as I seem to be intent on only remembering the incorrect information anyways.

For example, when someone was freaking out because BYOND allows you to use a boolean value as a numeric.
That someone was also me, again.

WealthyRadish

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10991 on: July 23, 2018, 06:37:41 am »

A nice thing about learning a highly permissive and broad language like C++ is that nearly every other language can then be learned just by "translating" the names and syntaxes the new language uses for the same concepts.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10992 on: July 24, 2018, 03:35:24 am »

People complain about "weird" stuff that Dream Maker does, almost all of which is perfectly normal stuff that other languages already do. For example, when someone was freaking out because BYOND allows you to use a boolean value as a numeric. Guess what? c and c++ also allow that, and professional coders exploit it to write much more confusing code than that BYOND stuff. Maybe the reason people complain about such everyday stuff in BYOND is because most BYOND coders haven't had to deal with c/c++ and other languages much.

My main complaint is just the insane way it does inheritance, scoping and the like. What happens if you make a class foo[/b] then define foo/bar/baz/fun()? Why, baz is implicitly defined as a class with method fun() which inherits from the implicitly-defined bar which inherits from foo, of course.

Most of the complaints I've seen are either 1. holdovers from C++ or 2. actually complaints about Space Station 13's codebase. For example, this abomination has more to do with me having to work around /tg/station's pre-existing blood code than anything to do with Dream Maker (for example, footprint code ended up being way easier to fix up, though iirc that had some strange consequences in some out-of-the-way locations).

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10993 on: August 09, 2018, 11:48:38 pm »

Code: [Select]
Simple task I set out for myself to help get better at coding was to display an image. I'm failing horribly again after picking this project up again. Can someone help?

[spoiler]
import tkinter
from PIL import ImageTk,Image

mainWindow = tkinter.Tk()

label = (mainWindow, "Valkur")

img = ImageTk.PhotoImage(Image.open("Valkyrie.jpg"))

mainWindow.create_image(20, 20, anchor=NW, image=img)

mainWindow.mainloop()

Errors:

Spoiler (click to show/hide)

Can someone explain to me this error a bit? If I understand the docs, the problem summary is the last bit right? Where it says that "FileNotFoundError" happened. I'm a little at a loss for words and while I did take some programming courses in college but if possible please explain as best as possible. I really don't want to be treated as anything but a noob in order to understand this.
« Last Edit: August 09, 2018, 11:56:05 pm by 3man75 »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10994 on: August 10, 2018, 12:08:55 am »

You seem to be missing the \ characters from the path.

The most likely reason is that \ is the escape code, for example when you write "\n" for a new line. A \ by itself always signifies that the next character is a special character code. \t for tab and \b for backspace are other examples.

A literal \ needs to be written as \\, so that it knows that it's representing the \ character itself and not being used to start a special code.

You can also write / instead of \ to specify paths (depends on the language), but it's good to be aware of the issue with using \.

This is also used to embed " characters inside a string, which is also delineated with " characters. You can use \" in those situations.
« Last Edit: August 10, 2018, 12:25:20 am by Reelya »
Logged
Pages: 1 ... 731 732 [733] 734 735 ... 795