Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 64 65 [66] 67 68 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100595 times)

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #975 on: December 09, 2012, 10:56:12 am »

ok, then let's go by trial and error.

remove the javax.swing.* import and all classes that come from that package from your code
Logged

Knight of Fools

  • Bay Watcher
  • From Start to Beginning
    • View Profile
    • Knight of Fools
Re: Programming Help Thread (For Dummies)
« Reply #976 on: December 09, 2012, 11:14:10 am »

That literally removes everything, since javax.swing.* holds all of the stuff needed for an applet to run.

I made another sample program to test it out, and I'm starting to think the problem's a bit more pervasive. I'm getting the error without the program even doing anything, just when it builds the panels in the applet. I'm going to delve into this a bit more, now that I know where I'm going. I was just hoping I was making some common rookie mistake.

Edit: Ofrik. It was some stupid mistake.

I was using "extends JLabel" instead of "extends JApplet", which made the entire thing go bust the second it loaded.

I'm going to stick my head in a hole in the ground now. Please excuse my shame.

Thanks for helping me figure that out.
« Last Edit: December 09, 2012, 11:18:44 am by Knight of Fools »
Logged
Proud Member of the Zombie Horse Executioner Squad. "This Horse ain't quite dead yet."

I don't have a British accent, but I still did a YouTube.

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #977 on: December 09, 2012, 08:32:46 pm »

Im stumped on this one...

Main class:
Spoiler (click to show/hide)

MapWorld:
Spoiler (click to show/hide)

Save file "default":
Spoiler (click to show/hide)

Im trying to load info from the text file using tokenization and use that to set tile type, needless to say it doesnt work, giving a nullpointerexception at at 114 (or the renderinuse part). Im exhausted so I cant explain more, but all help appreciated, this one has been annoying me for a while now. I can update it later, thanks again.
Logged
This conversation is getting disturbing fast, disturbingly erotic.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #978 on: December 10, 2012, 02:22:39 am »

Seriously, why don't you put the stack trace along with the code?

also, more generic tips: if it is a static constant, make it uppercase so when people read the code off the internet, it knows what is looking at.

for example mapWorld.baseX mapWorld.mapWidth etc.

and, don't call a class with the lowercase first letter, or it will look as a variable trough all the code.
    mapWorld[][] tilesAct = new mapWorld[mapWorld.mapHeight][mapWorld.mapWidth];


now, here is one error I can spot:
 for(int sizeCheck2 = 0; sizeCheck < mapWorld.mapWidth; sizeCheck2++) {

the check is on the sizeCheck and not sizeCheck2

I'll try and lock for more if nobody answers before. (now gotta go to work)
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #979 on: December 10, 2012, 07:45:24 am »

Well, sorry for poor code etiquette (I dont really know)

Anyways, thats not the problem, well not the main one, the problem is (im pretty surr) that the data values are not being stored properly. Even fixed, the stack trace is the same, which ill post later. (on phone now)
Logged
This conversation is getting disturbing fast, disturbingly erotic.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #980 on: December 10, 2012, 03:23:28 pm »

sadly problem are to be fixed one at a time as the bug is a moving target unless all other parts are proven to be working (which is impossible but I digress) :P
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #981 on: December 10, 2012, 03:49:20 pm »

well let me update you (once again ill upload the trace later, im on a diff pc)

If I replace

Code: [Select]
Tiles.renderInUse(x * 20 + mapWorld.baseX, mapWorld.baseY - y * 20, tilesAct[x][y].tileType(), 0);
with

Code: [Select]
Tiles.renderInUse(x * 20 + mapWorld.baseX, mapWorld.baseY - y * 20, 0, 0);
the map would render properly, however it would still have issues with storing other data like uniqStoreTest. So I conclude that either a.) the data is not being FED to the array correctly or b.) its not being stored/access correctly/being erased/or something. I did some testing, and set it up so the line (ie 0.0.0.0.0 etc.) is split into an array (using the split method) and that converted into an int which is then fed to the tilesAct array, this produces the same result, so im somewhat bambuzled (did I spell that right?) I am sure (within reason) that problem lies with loading the data, as when I had had the map hard-coded the same renderinuse method worked fine. Anyways, ill take another look later and post more info with updated class (and the damned stack trace) thanks again.
« Last Edit: December 10, 2012, 03:51:45 pm by Urist McScoopbeard »
Logged
This conversation is getting disturbing fast, disturbingly erotic.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #982 on: December 10, 2012, 04:23:31 pm »

fix da looop

also, check with this coded where you're failing:

>>>>>>>         if (tilesAct
  • [y] == null ) System.out.println("Missing chunk at "+x+","+y);

                        Tiles.renderInUse(x * 20 + mapWorld.baseX, mapWorld.baseY - y * 20, tilesAct
  • [y].tileType(), 0);

Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #983 on: December 23, 2012, 10:23:19 pm »

I've been tinkering around in Unity for a bit, and I finally am at the point where I think I can start working semi-competently on some small projects. I wanted to try having actual animated models, so I've also been learning how to animate with Autodesk Maya (yay, student licenses!). I have a script that lets you press 'w' to play a running animation on a stick figure model, while not pressing anything plays the idle animation. I tried to make it so that cross-fading works, and it... sort of does. If the timer is past 1 second or so when the keypress changes, it cuts abruptly to the other animation.

Code: [Select]
#pragma strict

public var noKeyTime : float;
public var noKeyAnimation : String;
public var wTime : float;
public var wAnimation : String;
public var time : float;
public var noKeysPressed : int = 1;
var transitoryAnimation : int = 0;
// 1 == wAnimation

public var anyKey : boolean;

function Update () {
if (Input.anyKeyDown == true) {
noKeysPressed = 1;
time = 0.0;
}

if (Input.GetButton("W")) {
if (Input.GetButtonDown("W")) {
animation.CrossFade(wAnimation, 1);
time = 0.0;
}
else {
time = time + Time.deltaTime;
if (time >= wTime) {
animation.Play(wAnimation);
time = 0.0;
}
}
}

else {
if (animation[wAnimation].enabled) { transitoryAnimation = 1; }
if (Input.anyKey == false) {
if (noKeysPressed == 1) {
if (transitoryAnimation == 1 && time >= wTime) { animation.Play(wAnimation); }
animation.CrossFade(noKeyAnimation, 1);
noKeysPressed = 0;
}
else {
if (time >= noKeyTime) {
animation.Play(noKeyAnimation);
time = 0.0;
}
}
time = time + Time.deltaTime;
}
}
anyKey = Input.anyKey;
}

noKeyTime is set to the length of the idle animation, noKeyAnimation is the name of the idle animation, wTime is the length of the running animation, wAnimation is the name of the running animation, and time is the timer.

It's an obtuse method, to say the least, so I was wondering if anybody knows a better way of playing and transitioning between animations.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #984 on: December 24, 2012, 05:57:01 am »

It's not all that obtuse. You probably want to reset your timer when you crossfade in your idle-animation, you probably get that jump since it's missing.

To avoid the need for doing much with timers at all, set animation.wrapMode to Loop instead of the default Once.
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #985 on: December 24, 2012, 12:41:05 pm »

It's not all that obtuse. You probably want to reset your timer when you crossfade in your idle-animation, you probably get that jump since it's missing.

To avoid the need for doing much with timers at all, set animation.wrapMode to Loop instead of the default Once.

It works! Thanks for the help!
Logged

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #986 on: December 26, 2012, 12:33:52 am »

In C#, is there a way to stop a console window from scrolling? I'm experimenting with drawing characters at arbitrary positions, and every time something goes to the bottom row, the console window scrolls down to show the empty line below it.
Code: [Select]
static void Main(string[] args)
        {
            Random rand = new Random();
            Console.SetWindowSize(80, 25);

            Console.WriteLine("Hello World!");

            while (true)
            {
               
                for (int y = 24; y >= 0; y--)
                {
                    for (int x = 79; x >= 0; x--)
                    {
                        //Thread.Sleep(1);
                        Console.ForegroundColor = RandomConsoleColor(rand);
                        Console.BackgroundColor = RandomConsoleColor(rand);
                        Console.SetCursorPosition(x, y);
                        Console.Write("#");
                        Console.SetWindowPosition(0, 0);
                    }
                }
            }
        }
As a quick hack, I can use SetWindowPosition to recenter the screen after every hash, but this really slows the thing down once there are a few lines of them. Is there a proper way to do this?

EDIT: Ah, apparently I can use Console.SetBufferSize to make the buffer the same size as the window, which removes the scrollbars altogether. The only problem now is that when I write something to the bottom right corner, I get a newline, and the whole mess of colorful characters shifts by one row. I guess I could leave the buffer one wider horizontally, which gives me this tacky horizontal scrollbar but seems to function.
« Last Edit: December 26, 2012, 09:17:56 am by Soadreqm »
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #987 on: January 02, 2013, 03:03:06 pm »

For some inexplicable reason, Unity increases cameraScript.targetInt twice whenever tab is pressed with this script:

Code: [Select]
#pragma strict

public var objectName : String;
private var target : String;
public var mainCamera : GameObject;
private var cameraScript : MouseOrbit;

function Start () {
cameraScript = mainCamera.GetComponent(MouseOrbit);
}

function Update () {
target = cameraScript.targetName;

if (Input.GetButtonDown("Tab")) {
cameraScript.targetInt += 1;
Debug.Log(cameraScript.targetInt);
}

if (objectName == target) {
if (Input.GetButtonDown("W")) {
if (mainCamera.transform.eulerAngles.y < 45 || mainCamera.transform.eulerAngles.y > 315) {
transform.position.z += 1;
}
if (mainCamera.transform.eulerAngles.y < 135 && mainCamera.transform.eulerAngles.y > 45) {
transform.position.x += 1;
}
if (mainCamera.transform.eulerAngles.y < 225 && mainCamera.transform.eulerAngles.y > 135) {
transform.position.z -= 1;
}
if (mainCamera.transform.eulerAngles.y < 315 && mainCamera.transform.eulerAngles.y > 225) {
transform.position.x -= 1;
}
}

if (Input.GetButtonDown("A")) {
if (mainCamera.transform.eulerAngles.y < 45 || mainCamera.transform.eulerAngles.y > 315) {
transform.position.x -= 1;
}
if (mainCamera.transform.eulerAngles.y < 135 && mainCamera.transform.eulerAngles.y > 45) {
transform.position.z += 1;
}
if (mainCamera.transform.eulerAngles.y < 225 && mainCamera.transform.eulerAngles.y > 135) {
transform.position.x += 1;
}
if (mainCamera.transform.eulerAngles.y < 315 && mainCamera.transform.eulerAngles.y > 225) {
transform.position.z -= 1;
}
}

if (Input.GetButtonDown("S")) {
if (mainCamera.transform.eulerAngles.y < 45 || mainCamera.transform.eulerAngles.y > 315) {
transform.position.z -= 1;
}
if (mainCamera.transform.eulerAngles.y < 135 && mainCamera.transform.eulerAngles.y > 45) {
transform.position.x -= 1;
}
if (mainCamera.transform.eulerAngles.y < 225 && mainCamera.transform.eulerAngles.y > 135) {
transform.position.z += 1;
}
if (mainCamera.transform.eulerAngles.y < 315 && mainCamera.transform.eulerAngles.y > 225) {
transform.position.x += 1;
}
}

if (Input.GetButtonDown("D")) {
if (mainCamera.transform.eulerAngles.y < 45 || mainCamera.transform.eulerAngles.y > 315) {
transform.position.x += 1;
}
if (mainCamera.transform.eulerAngles.y < 135 && mainCamera.transform.eulerAngles.y > 45) {
transform.position.z -= 1;
}
if (mainCamera.transform.eulerAngles.y < 225 && mainCamera.transform.eulerAngles.y > 135) {
transform.position.x -= 1;
}
if (mainCamera.transform.eulerAngles.y < 315 && mainCamera.transform.eulerAngles.y > 225) {
transform.position.z += 1;
}
}
}
}

The only part of the code that affects that variable is this:

Code: [Select]
if (Input.GetButtonDown("Tab")) {
cameraScript.targetInt += 1;
Debug.Log(cameraScript.targetInt);
}

I'm pretty sure that should only have registered one increase, but it seems to insist on two. Is there some obvious error I'm making that I can't see right in front of me? Because I've tried everything I could think of and yet this problem persists.

EDIT: Nevermind, figured it out. It was because two objects with this script were in the scene, leading to the number being incremented once for each object.
« Last Edit: January 02, 2013, 06:12:06 pm by Araph »
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #988 on: January 07, 2013, 01:47:10 pm »

Back again with another programming question.

Code: [Select]
transform.position.x += Mathf.Sin(transform.rotation.y) * speed * Time.deltaTime;
transform.position.z += Mathf.Cos(transform.rotation.y) * speed * Time.deltaTime;
transform.position.x += Mathf.Cos(transform.rotation.y) * sideSpeed * Time.deltaTime;
transform.position.z += Mathf.Sin(transform.rotation.y) * sideSpeed * Time.deltaTime;

This is supposed to make the camera move along the x axis and z axis without moving up and down along the y axis. I thought I had my sines and cosines right, but it behaves... strangely, to say the least. Speed and sideSpeed are increasing and decreasing fine, so it's not a problem with them.
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #989 on: January 07, 2013, 01:54:43 pm »

Chances are you're looking for -= Sin on the very last line, instead of += Sin. If you look at the 2d rotation matrix http://en.wikipedia.org/wiki/Rotation_matrix, notice the change in sign on the sine on the first row of the matrix.
Logged
Pages: 1 ... 64 65 [66] 67 68 ... 91