This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-07-31 17:45:23

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

C++ - Integers Randomly Changing Values?

I am working on a game right now (if you want to learn more about it, find the thread on Coder's Shed  wink  ) and have been running into many issues. Some segmentation faults which I have fixed, and some other issues. Namely, in making a procedurally generated world. It seems that the integer values in my program are randomly changing. Does anyone have an explanation for this? They are not global variables, they are variables specific to a class. This problem keeps getting in my way and there is no explanation.

Last edited by 16Skittles (2012-07-31 17:45:44)


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#2 2012-07-31 17:59:32

videogame9
Scratcher
Registered: 2008-05-12
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

I think we might need to see your code before we can help fix the problem.


http://img641.imageshack.us/img641/4118/newvg9logo.png
QUOTE OF THE RIGHT NOW: why are we arguing about dead babies? -videogame9

Offline

 

#3 2012-07-31 18:24:14

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

I don't really think that would help you very much, I am not changing it within my code. I have one thing to try (that will actually clean up the code) and I am about to leave on a small trip to Chicago. When I get there I will try to fix it.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#4 2012-07-31 18:56:34

Ecliptic
Scratcher
Registered: 2012-02-27
Posts: 500+

Re: C++ - Integers Randomly Changing Values?

I think you might find more help on Coders' Shed or Stack Overflow.


If you can read this you are in range.

Offline

 

#5 2012-07-31 21:59:32

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

Ecliptic wrote:

I think you might find more help on Coders' Shed or Stack Overflow.

My logic posting it here was that anyone not on CS would be here, and since CS is mostly an extension of the Scratch community, they would be here too.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#6 2012-07-31 22:13:52

Ecliptic
Scratcher
Registered: 2012-02-27
Posts: 500+

Re: C++ - Integers Randomly Changing Values?

16Skittles wrote:

Ecliptic wrote:

I think you might find more help on Coders' Shed or Stack Overflow.

My logic posting it here was that anyone not on CS would be here, and since CS is mostly an extension of the Scratch community, they would be here too.

Stack Overflow?


If you can read this you are in range.

Offline

 

#7 2012-08-01 07:27:59

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

Skittles, make sure you're not using local variables instead of global.

i.e.

x = 20
{
local x = 29// or w.e it was

x;
}


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#8 2012-08-01 14:16:07

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

bbbeb wrote:

Skittles, make sure you're not using local variables instead of global.

i.e.

x = 20
{
local x = 29// or w.e it was

x;
}

What? My variables are included in the declaration of the class. Like this: (not the full class declaration, just a part of it)

Code:

Class sector{
Public:
Sector(int x, int y);
Int x;
Int y;
Void foo();
Tile[10][10] tiles;
}

Void foo(){

//not going to post all of the code, basically it loops through and take
For(int repeatx=0; repeatx<10; repeatx++){

For(int repeaty=0; repeaty<10; repeaty++){
//this renders each tile. The parameters are for the offset, so that the different sectors //render in different places.
tiles[repeatx][repeaty].update(x*640, y*640);
}

}

}

http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#9 2012-08-02 21:16:40

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

bump.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#10 2012-08-03 14:48:46

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

How much code do you have? Would it be possible to paste some?

You would get more help if you post this stuff in AT so we actually see it.  tongue

Last edited by MathWizz (2012-08-03 14:55:08)


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#11 2012-08-03 22:35:38

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

MathWizz wrote:

How much code do you have? Would it be possible to paste some?

You would get more help if you post this stuff in AT so we actually see it.  tongue

Advanced Topics? Isn't that specifically for advanced Scratch or Scratch Modification topics?


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#12 2012-08-05 09:05:25

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

I don't know if it is possible, but it may be that the integer is simply getting corrupted by the number of times it is accessed.

Let's assume a frame rate of 30 Frames/second.
That is 30 updates of the level and each sector.
Each update cycles through 100 tiles and accesses the integer x each time.
1 second = 3,000 times accessing the integer.

Could an insane amount of times accessing a variable cause it to break?


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#13 2012-08-05 09:17:50

poopo
Scratcher
Registered: 2009-09-20
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

16Skittles wrote:

I don't know if it is possible, but it may be that the integer is simply getting corrupted by the number of times it is accessed.

Let's assume a frame rate of 30 Frames/second.
That is 30 updates of the level and each sector.
Each update cycles through 100 tiles and accesses the integer x each time.
1 second = 3,000 times accessing the integer.

Could an insane amount of times accessing a variable cause it to break?

I really doubt it. You should make it cout the variable every loop so you can see when it's value is being changed, that always works for me.


http://i45.tinypic.com/28rnqki.jpg

Offline

 

#14 2012-08-05 09:22:14

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

poopo wrote:

16Skittles wrote:

I don't know if it is possible, but it may be that the integer is simply getting corrupted by the number of times it is accessed.

Let's assume a frame rate of 30 Frames/second.
That is 30 updates of the level and each sector.
Each update cycles through 100 tiles and accesses the integer x each time.
1 second = 3,000 times accessing the integer.

Could an insane amount of times accessing a variable cause it to break?

I really doubt it. You should make it cout the variable every loop so you can see when it's value is being changed, that always works for me.

It's an OpenGL application, and when I try to use cout<<"Hello World"; nothing happens.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#15 2012-08-05 11:25:10

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

AT isn't just for scratch mods
It can be for topics like this

As for your problem it might be a coding error


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 

#16 2012-08-05 12:00:32

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

Maybe you can help me with this:
I am trying to make a constructor for my sector class. I have it set out like this:

Code:

sector::sector(int getx, int gety){
x=getx;
y=gety;
}

But when I compile, it shows an error:

Code:

No matching function to call for Tile::Tile()

While searching for a solution to my main problem, I found This. This seems to be the same problem I am finding, but can't be sure.  hmm


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#17 2012-08-08 12:51:54

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

Re: C++ - Integers Randomly Changing Values?

that error sounds like you havent defined it properly


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 

Board footer