Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 499 500 [501] 502 503 ... 795

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

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7500 on: June 03, 2015, 01:10:23 am »

btw, passing the cointotal directly in like that is not a great design. Since it's just getting a copy of the coins int, then you'd have to send any updated coins value as a return value, which makes your client code really messy and also error prone if you forget to use the return value, and you end up doubling up e.g. player.coinTotal = gameShop.shopFunction(player.coinTotal) which is just basically writing everything twice, so it's not good. And of course you can only update one thing this way (coinTotal), which would make it difficult if e.g. there were multiple things you could buy in the shop.

The best solution is to pass a reference to the player object in. Passing the cointotal from the player actuall takes 3 times as long. If you plass &player, it just passes a copy of memory address of the player in as the parameter. if you pass player.coinTotal, it takes the player memory address, calculates the coinTotal memory address from within that, then looks up that memory address to get the int, then passes a copy of that. So much slower!

I set up an example 'interface' for the player class for getting and setting the cointotal. Then the shop would handle all the shopping and adjustments within itself, and you also cater for having different characters go shopping without needing extra code.

Spoiler (click to show/hide)
« Last Edit: June 03, 2015, 01:34:32 am by Reelya »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7501 on: June 04, 2015, 02:24:15 pm »

In Unity, I'm trying to create a simple mission system that stores a title and description for the mission. I created a class called missionProfile, and each mission is itself an instance of missionProfile. I just want to add each instance to a static list within missionProfile. No matter what I do, however, I just can't get the stupid mission profiles to go into any sort of list.

Here's what it looks like now. This is probably the sixth configuration I've tried. I gave up on the static thing because now I'm just trying to get it to work in any capacity, I don't care about static or non-static. I'm officially stumped.

Spoiler: missionProfile.cs (click to show/hide)

And here's a GUI script that I wrote to see if it's working. Attach it to a Panel with two text children named "title" and "description".

Spoiler: MissionPanelScript.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.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7502 on: June 04, 2015, 02:26:53 pm »

You know, sometimes I'm really glad I don't use Unity. In this context, "sometimes" means every time I see someone use Unity.
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7503 on: June 04, 2015, 02:33:10 pm »

I'm thinking it's more of a c# problem, or a "me being stupid and missing something that will be really obvious when somebody points it out" problem :P
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 #7504 on: June 04, 2015, 03:31:50 pm »

I tried running your code. Issue #1 is from C# lists. The list holder must be initialized with "new" or you get an error:

randoms = new List<missionProfile> (); // is missing and must be called whether the list is static or normal

This fixes all the main problems. Lists and arrays are not handled like c++ arrays/vectors/lists and must be manually set up like this in C#
« Last Edit: June 04, 2015, 04:18:15 pm by Reelya »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7505 on: June 04, 2015, 04:19:33 pm »

I tried running your code. Issue #1 is from C# lists. The list holder must be initialized with "new" or you get an error:

randoms = new List<missionProfile> (); // is missing and must be called whether the list is static or normal

This fixes all the main problems.

I could have sworn that I had tried that before. Must have missed something then, because now it's working fine. Thank you! I should probably read more about c# in general instead of just Unity stuff.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7506 on: June 04, 2015, 10:11:39 pm »

you probably also want to keep your mission list separate from the mission class, or at least have everything related to the list static, unless you want nested sub-missions, I guess.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7507 on: June 04, 2015, 11:00:12 pm »

Yup. Actually I'd recommend to make a separate "missions" class and hide all the implementation details for the list inside of that. There's even a technique where you intercept the requests for the items, and check if the container has been implemented, and if not then you do the "new" call right there. So containers only get instantiated as needed. This is a nice way to do things for data structures which are not accessed repeatedly since the tiny extra overhead isn't going to hurt anything.
« Last Edit: June 04, 2015, 11:02:12 pm by Reelya »
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7508 on: June 05, 2015, 02:39:23 pm »

Code: [Select]
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>Car Object Animation with Callback</title>
    <style type="text/css">
        body {
            background-color: #AADDCC;
        }
        #img2 {
        position:absolute;
        right:253px;
        bottom:0px;
        z-index:-1;
        }
#img3 {
        position:absolute;
        right:253px;
        bottom:0px;
        z-index:-1;
        }
        #clouds {
        position:absolute;
        right: 55px;
        top:55px;
        z-index:99;

#clouds2 {
        position:absolute;
        right: 75px;
        top: 35px;
        z-index:99;

#clouds3 {
        position:absolute;
        right: 145px;
        top:30px;
        z-index:99;

#clouds4 {
        position:absolute;
        right: 100px;
        top:85px;
        z-index:99;

       
        }
    </style>

</head>
<body style="overflow: hidden">
    <img alt="cloud" id="clouds" src="clouds.png" />
<img alt="cloud" id="clouds2" src="clouds.png" />
<img alt="cloud" id="clouds3" src="clouds.png" />
<img alt="cloud" id="clouds4" src="clouds.png" />
    <img alt="car" id="img2" src="car1.png" />
<img alt="car" id="img3" src="car1.png" />
            <script>

                // create  Car factory using the constructor function
                function Cars(id) {
                    this.speed = Math.floor((Math.random() * 100) + 1); // generate a random number between 1 and 100 //prompt("Enter a number between one and 100", 75);
                    this.speed = 101 - this.speed;// inverse the speed to be used in the built in setTimeOut method
                    this.car = document.getElementById(id);//grab onto the image
                    this.carCounter = -254;// set the car counter which will control the pixel location
                    this.lapCounter = 0; // used to count the laps

                    // The Call back function is to count laps and to learn about Call back functions
                    this.callbackFun = function (car) {
                        alert(" FInished lap number " + car.lapCounter + " for car " + id);
                    }

                    // the moviit function changes the css right property and accepts a function
                    this.moveIt = function (callback) {
                       
                        this.carCounter += 3;
                        this.car.style.right = this.carCounter + "px";

                       

                        var _this = this;// Becase this is the this we want as it changes once inside the setTimeOut function

                        if (this.carCounter < (screen.width+254)) {
                            setTimeout(function () { _this.moveIt(callback) }, this.speed);// send moveIt the callback function as an argument


                        } else {
                            this.lapCounter++;// increment the lap Counter

                            //callback(this); // Call the call back function which gives alert for each lap


                            //alert(" Lap number " + this.lapCounter);// visual display of the lab counter
                            this.carCounter = -254;// reset the car Counter back to -400
                            setTimeout(function () { _this.moveIt(callback) }, this.speed);
                        }

                    }// end of move it function


     
                };

function clouds(id) {
                    this.cloudSpeed = Math.floor((Math.random() * 100) + 1); // generate a random number between 1 and 100
                    this.cloudSpeed = 101 - this.speed;// inverse the speed to be used in the built in setTimeOut method
                    this.cloud = document.getElementById(id);//grab onto the image
                    this.cloudCounter = -100;// set the car counter which will control the pixel location
this.lapCloudCounter = 0; // used to count the laps

                    // the moviit function changes the css right property and accepts a function
                    this.moveCloud = function (callback) {
                       
                        this.cloudCounter += 3;
                        this.cloud.style.right = this.cloudCounter + "px";

                       

                        var _thisCloud = this;// Becase this is the this we want as it changes once inside the setTimeOut function

                        if (this.cloudCounter < (screen.width+100)) {
                            setTimeout(function () { _thisCloud.moveCloud(callback) }, this.cloudSpeed);// send moveIt the callback function as an argument


                        } else {
                            this.lapCloudCounter++;// increment the lap Counter

                            //callback(this); // Call the call back function which gives alert for each lap


                            //alert(" Lap number " + this.lapCounter);// visual display of the lab counter
                            this.carCounter = -100;// reset the car Counter back to -400
                            setTimeout(function () { _this.moveCloud(callback) }, this.cloudSpeed);
                        }

                    }// end of move it function


     
                };



                var myCar2 = new Cars('img2');
                myCar2.moveIt(myCar2.callbackFun);

var myCar3 = new Cars('img3');
                myCar3.moveIt(myCar3.callbackFun);
   
var myCloud = new clouds('clouds');
                myCloud.moveCloud(myCloud.callbackFun);

var myCloud2 = new clouds('clouds2');
                myCloud2.moveCloud(myCloud2.callbackFun);

var myCloud3 = new clouds('clouds3');
                myCloud3.moveCloud(myCloud3.callbackFun);

var myCloud4 = new clouds('clouds4');
                myCloud4.moveCloud(myCloud4.callbackFun);

   
    </script>

</body>
</html

Trying to get clouds 2-4 to move, but they sit in the corner not doing anything. And unike the cars, the cloud that DOES move, doesn't return. I'm not good with this, but I'm trying to figure it out. Any tips and idea what I'm doing wrong?
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7509 on: June 05, 2015, 03:09:40 pm »

The cloud isn't returning because you cut and pasted the cars code, and you forgot to change one of the words "car" to "cloud". It's resetting the car counter inside the cloud.

Also, minor, but you forgot to change some this.speed references to this.cloudSpeed
« Last Edit: June 05, 2015, 03:26:22 pm by Reelya »
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7510 on: June 05, 2015, 03:26:28 pm »

The cloud isn't returning because you cut and pasted the cars code, and you forgot to change one of the words "car" to "cloud". It's resetting the car counter inside the cloud.

... Whoops... What about the three idle clouds? Any idea?
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7511 on: June 05, 2015, 03:43:03 pm »

I'm not sure about that yet. I'm playing around with things. I've found that if you rig up the 1st cloud to the "Cars" class and move it wraps around properly, just by changing it to this:

var myCloud = new Cars('clouds');
myCloud.moveIt(myCloud.callbackFun);

Works fine. Which implies you have some cut/paste errors in copying the code. So you could just use the same code to move all items, or you can try copy pasting the Cars code again - but just avoid renaming all the things this time or you'll probably get the same type of errors again.

One big issue is that you changed all the variables inside the cloud factory to be "CloudXYZ" and "CloudThingy" etc. This is not necessary and that type of copy paste editing causes the types of errors you're getting. Give the items inside a factory generic names, then copy the factory for a new type, but keep the internal names the same. Then you basically dodge the source of these sorts of errors.

~~~

BTW I have Inspect Element open in FireFox while your script is running. The right value of the cloud images is actually changing every frame. It's just not moving them on the screen. Maybe it's something to do with their vertical location ... testing ....
« Last Edit: June 05, 2015, 03:49:15 pm by Reelya »
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7512 on: June 05, 2015, 03:50:49 pm »

I did mess with their vertical placement, so I'll fiddle with that
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7513 on: June 05, 2015, 03:56:14 pm »

Actually I'm looking at the elements in the FireFox inspector, and it's saying that clouds 2-4 don't have the correct ID attached to them. cloud1 and the cars all show the block of values for the id tag on the right, but the other clouds do not. However, all the clouds right values are being updated properly. So it's something going screwy with the display code in the browser.

I figured it out - you don't have closing brackets on your CSS styles.

I recommend strict indentation e.g.

#clouds
{
    // things about clouds
}

#clouds2
{
    // things about clouds2
}

as it would have been much clearer that the brackets were missing
« Last Edit: June 05, 2015, 03:58:45 pm by Reelya »
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7514 on: June 05, 2015, 04:00:19 pm »

Huzzah! It now works! Now to make it so they aren't doggy piling on top of one another... Thanks!
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.
Pages: 1 ... 499 500 [501] 502 503 ... 795