Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 689 690 [691] 692 693 ... 795

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

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10350 on: February 10, 2017, 01:43:32 pm »

Was trying to log into my Gmail from a Python interpreter using IMAP. Gmail kept telling me "Nuh-uh, log in from gmail.com" even though I have IMAP enabled and even briefly turned on a feature allowing "less secure apps" to access my mailbox. No dice.

I wanted to write a script/service that would echo emails from my student email to my personal account on some set interval, because I've never used an email client and don't intend to start now.

EDIT: Tried it again and it magically worked. No idea what I did differently, but I'll hardly be able to give this to other students like I was planning. Pain in the butt to set up.


I understand that Gmail has been trying to move people away from using their own clients, or something.


This was a sticking point for me when I tried to use Calibre again a couple of months ago.


In any case, that's obviously old news, but keep in mind that Google might be doing this for their own reasons, and I'm sure that you've used the library correctly for the connection, so keep in mind those security layers that Google might have outside of the IMAP/SMTP protocols might mean that you've not done anything wrong.

Krevsin

  • Bay Watcher
  • [RAINBOWS:REQUIRED]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10351 on: February 11, 2017, 08:13:22 am »

So I'm doing a pet project in Unity 5.5 and I've written up the framework for a system whereby a player can interact with an object or NPC in the world by clicking on them. I've been following this tutorial. However, when I click on an interactable object in the game for the first time, it interacts with all the interactable objects present in the scene which is rather troubling. After that it proceeds to work normally. The entire system is based on the following two scripts,

the first, used for moving the player around and seeing if a clicked object is interactable.
Spoiler (click to show/hide)
and the second one that handles the actual interaction.

Spoiler (click to show/hide)

Any help would be much appreciated.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10352 on: February 11, 2017, 09:53:03 am »

Put more debug items in there, to see how often lines of code are being triggered. Often you assume a line of code is being triggered more than once but the error is in fact in a different function or script. So never assume what's going on, put debugs at the top of each function that print the name of the object + function name. It's a really handy trick to trace the problem down.

 When you say it's interacting with all interactable objects, exactly what happens, are they all calling Debug.Log ("Interacting with base class.")? If so, perhaps the assumptions in the if statement in the Update aren't true. Maybe the playerAgent reference isn't null, when it needs to be null, that would cause the if statement to trigger wrongly the first time, but then "hasInteracted" gets set to true, and then it won't trigger again unless you click on it.
« Last Edit: February 11, 2017, 09:57:11 am by Reelya »
Logged

Krevsin

  • Bay Watcher
  • [RAINBOWS:REQUIRED]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10353 on: February 11, 2017, 09:56:16 am »

I did that and all the scripts seemed to work just fine while still interacting with all the interactables in the scene at once.

Then in a fit of desperation I attached the script to the actual player model instead of the player parent object and now it works fine? Weird.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10354 on: February 11, 2017, 09:58:23 am »

What' was the relation between the player parent object and the Interactable objects?

Because you've got virtuals in there, it's possible a derived class could change the assumptions you're making, e.g. if another Object inherited from Interactable and set the player object itself, it wouldn't be null when it needed to be.

If you want to test it again, you can change it back, but get each Interactable to tell you whether their playerObject link is false/true etc.
« Last Edit: February 11, 2017, 10:00:30 am by Reelya »
Logged

Krevsin

  • Bay Watcher
  • [RAINBOWS:REQUIRED]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10355 on: February 11, 2017, 10:34:12 am »

The Player parent object is just an Empty containing the player model. The Interactable and it are only linked when I click on an object with the appropriate tag and the game paths the player to the object, and when at a certain distance from the object it runs the Interactable script which basically triggers the Virtual, which is then overriden based on the type of object I've clicked (item, NPC, signpost etc.)

The override scripts are all exactly the same for now:

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickupItem : Interactable {

public override void Interact(){
Debug.Log ("Interacting with Item");
}

}

This basic code is exactly the same, with the only difference being the name of the script and the 'Item' in the debug log is replaced by an appropriate word (NPC, signpost etcetera).

I did further testing, reapplied the WorldInteraction script to the Player parent object, removed it from the model and set up the code with a bunch of notifications to the debug log menu and the only thing I've learned from it is that for some reason when I start up the game, the game immediately thinks I've interacted with all the objects with the Interactable Object tag. After that it works normally.

It works just fine if I just put the WorldInteraction script on the actual player model instead of its parent empty. So I'm assuming this might be a bug with Unity itself or just a side effect of the way Unity does things.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10356 on: February 11, 2017, 10:57:29 am »

Not a Unity bug. I'm certain of that. They've been developing this a lot longer than you've been making your program. Some program that took a few minutes to cook up is much more likely to have a bug than an engine that's been in development for years and is used in thousands of game studios around the world.

What you should do is actually sort out why it happened. learning more about how Unity works will help you avoid similar bugs in the future.

So when you say "they think the objects have been interacted with" you haven't actually explained how you know that. Back-tracing exactly what happens will show you the error. Which is the first function that's called when it's not supposed to?
« Last Edit: February 11, 2017, 11:11:13 am by Reelya »
Logged

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #10357 on: February 11, 2017, 11:21:04 am »

Remember, print statements are your friend. I had a bug at work the other day because two things were out of alignment at the third decimal place, which meant it was impossible to tell visually that anything was wrong - except that something else was behaving as though they were out of alignment. I spent an hour or so debugging, and then when I sprinkled print statements into my code to check what it was doing I could instantly isolate the issue.

What you think is happening is not the same as what is happening. Similarly, what it looks like is happening is not the same. The only way to be absolutely certain of what's happening is to have the program tell you explicitly.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

Krevsin

  • Bay Watcher
  • [RAINBOWS:REQUIRED]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10358 on: February 11, 2017, 11:24:06 am »

Well when I start the game and try to interact with a NPC, the debug log fills with these messages:

"PlayerAgent Got"
"PlayerAgent Got"
"Clicked"
"Got Interaction Info"
"Moving to Interaction"
"Object is Interactable, moving to object"
"Player hasn't interacted and there isn't a pending path" (repeated a lot because it writes it for every single frame while en-route to interaction)
"Interacting with Item"
"Interacting with NPC"
"Interacting with NPC"
"Interacting with Signpost"
"Initializing Interaction"

When I try to interact with another object after that, it works just fine (merely reports the single object that's being interacted with instead of all of them).

Code with all the times where stuff gets written down in the debug log:
Spoiler (click to show/hide)

edit: after sleeping on it for the night and trying again today, I seem to be unable to replicate this for some reason which just makes me think more that this was in fact a Unity bug.
« Last Edit: February 12, 2017, 02:06:25 am by Krevsin »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10359 on: February 12, 2017, 03:06:52 am »

Now you're blaming multiple things on the people who created Unity.

Don't you think that it's more likely you're in denial about your own sloppy game code? I don't mean to be rude, but you've done that twice now for two different problems, so you might want to rethink your logic process.

Which goes back to what I said. When you had the "unexplained" problem, by merely blaming someone else for it, you failed to work out why a really basic fuck-up on your part was happening, and because of that you didn't deepen your understanding of the engine, and of course, next time you have a similar issue, you don't delve into the "why" either, but blame some other mystical "Unity Bug" in what is now probably the world's most widely used commerical game engine.

At this point I've built about 40 game demos in Unity ranging from Tic Tac toe up to including some seriously complex shit, each time there were bugs, every time it was my code and not "Unity Bugs". Your code is junior-level. There's no way it's not the cause of your own bugs. Again, I'm not trying to be rude here, but you need a reality check, and I'm not going to spend time helping people who keep blaming the tools rather than improve by taking the time to work out why things are happening.

Unity is after all, a general purpose engine. You can make any existing or even hypothetical type of game inside Unity. Therefore Unity can't know what's "right" for your game. It only follows the code you typed in, which can be the code for any hypothetical game genre that could exist. So Unity has no way of going "oops, I didn't draw the selection box on that unit" because Unity has no built-in concept for "Unit" or "Selection Box" or any idea when you might want the selection box or not want the selection box. It's your code's job to create these things and wire them up so that they behave like you think your RTS "should" behave. Unity only reads the code you typed, it has no knowledge of your "authors intent". If the selection box on a unit disappears when you didn't want it to, that's because somewhere your code said for that to happen, at least in 99.99% of cases: Unity was just following the written instructions.
« Last Edit: February 12, 2017, 03:36:51 am by Reelya »
Logged

Krevsin

  • Bay Watcher
  • [RAINBOWS:REQUIRED]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10360 on: February 12, 2017, 03:40:26 am »

I'm not blaming anything on anyone, it's just strange is all  ???

The code works fine if I attach it to the player model and now for some reason it also works if I attach it to the parent empty.

All I did to make that change was shut down Unity and restart it in the morning to see if I can do some further testing and try to find out the cause of this weird bug whereupon I discovered that it now works just fine regardless of where I attach the code to. I have made no changes to the code.

Plus it's not even my code, it's the exact same code I got from this series of tutorials, more specifically the first three videos. The only notable difference is that in Unity 5.5 NavmeshAgent is a subset of UnityEngine.AI. The rest is unchanged from the videos.

I'm not blaming anything on anyone and I've only ever had one problem. I don't know where you think I claimed to have another problem, but my last few posts were all discussing the same problem, one that seemingly went away on its own without me doing anything with the code except throwing in a bunch of debug.log events into it to try and figure out what was going on. Hence why I concluded that this is probably a Unity bug.

Which is not an accusation nor passing of blame, just a way for me to explain this peculiar event which somehow fixed itself without me changing any code, just placing it in a different place in the hierarchy and then restarting Unity not only fixed it but also made it so that I cannot recreate the original bug in the first place. It's weird and I cannot quite explain it because I don't even know what exactly happened to either bring this on or fix it.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10361 on: February 12, 2017, 04:00:00 am »

Ah sorry, it sounded like you were bringing up another issue you had then saying that it was also caused by a Unity bug. I'm sensitive to that because I've dealt with people who do that before.

BTW, here's my assumption on what your bug was about: each Interactable has a "playerAgent" variable, which is public. Therefore it's settable in the Unity Inspector. Whatever value you set inside the Inspector is the starting value when "Play" is hit. So if you had ever linked the Interactable's playerAgent value to the actual playerAgent, they always start as connected. When you removed the correct script from the parent object and put in on another object, that could have broken the connection inside the Inspector, setting all references back to "null", which is why you can't replicate the problem.

Now, if you look at the code inside Interactable.Update:
if(!hasInteracted && playerAgent != null && !playerAgent.pathPending)\
- hasInteracted starts as false (only because it's never set)
- playerAgent is never actually initialized to null - a glaring fuckup from the writer of the code.
- playerAgent.pathPending is controlled by playerAgent

So since playerAgent is public i.e. can be overridden inside the editor, and never actually set inside the code, then if the third part becomes true, it could trigger for all Interactables at once.

Here are tips to avoid / find these types of bugs:
- look in the editor to check what starting value public fields have
- make sure all needed values are explicitly initialized (in Awake or Start).
- don't make internal stuff public, since that can override settings you put in the definition of a field

also you can use variables inside debug statements to make them more helpful. e.g. at the top of "MyFunction" inside an object "Debug.Log(this.name + ": MyFunction)" is more helpful. And print out the relevant values before if statements if things are being triggered when they're not supposed to. It's usually because the expected value wasn't actually set properly.
« Last Edit: February 12, 2017, 04:17:46 am by Reelya »
Logged

Krevsin

  • Bay Watcher
  • [RAINBOWS:REQUIRED]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10362 on: February 12, 2017, 04:03:36 am »

Thanks for the advice, I'll keep it in mind as I continue with this pet coding project.  :D
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10363 on: February 12, 2017, 04:08:31 am »

The fixable lesson from this problem is that you should always have an awake function in every object that manually sets all variables to their expected values, especially if they're "public" because "public" values can in fact have their starting values changed outside the code.

Even better, if they're a basic type or custom class with a meaningful constructor (ie not a MonoBehaviour) just set it in the field declaration. That way the variable won't appear to be one thing when the game's not in play mode, then change once you enter play mode. Also if a script has useful default values, like a control script where you've already worked out a movement speed that feels good, if you have those set in the declaration then they'll automatically be applied whenever you add the component to a GameObject.

Also, if Reelya means Monobehavior.Awake() and not just any function that runs on scene start, the order in which scripts are initialized can bite you depending on how many and what kind of references to other objects you're setting up (ie, if one Awake function is depending on something that happens in another script's Awake function and bad luck causes them to happen out of the order that you'd prefer). It's not un-work-around-able but something to keep in mind.
« Last Edit: February 12, 2017, 04:10:27 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.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10364 on: February 12, 2017, 04:29:34 am »

In those cases, I use my own "Init" function in each object, they then get called from a master object.

BTW itisnotlogical the default value in the variable's code declaration can in fact be overridden by the Inspector value, which can be a pain when you change its default value in code and nothing happens, so generally you want to avoid that situation since it can lead to wasting time going "why isn't this change working" when the code change is in fact being ignored on some, but not all, objects, because you manually overrode it on the Editor side.

I prefer now to make a Scriptable Object which has a set of parameters in it for another object. You can them just pick which set of defaults each object is using on the fly, and Scriptable Object data can in fact be changed while the game is running, and retains the edits when you hit stop. Scriptable Objects can also have "defaults" coded in on the code-side, to populate the fields correctly, but since they always require an actual implemented version to be used at runtime, there's no confusion (needing to jump back and forth between code and the editor) about what the starting settings are.
« Last Edit: February 12, 2017, 04:33:02 am by Reelya »
Logged
Pages: 1 ... 689 690 [691] 692 693 ... 795