Object/Sprite Private Variables Messed up..How to fix?

For questions about using Classic.

Post » Fri Jul 04, 2008 3:19 am

I have an Object/Sprite that has its Private Variables Messed up.
One of the Private Variables is like a black hole. It eats the Private Variables under it. Then the bad variable has the data for the the variable under it. This is then repeated for the rest of the variables under it.

It Looks like this:

Object/Sprite
Private Variables :
test1 : 111
test2 : 222
Bad : 0
test4 : 444
test5 : 555
test6 : 666

when you run the game/debug you get this:
Object/Sprite
Private Variables :
test1 : 111
test2 : 222
Bad : 444
test4 : 555
test5 : 666
test6 : 0

You can check it out in my cap. In the "Main Layout" Object "tankbottom". The bad variable is "AngleToEnemy".
I have tried to delete it, as it is not used in any of my code right now. But when I do the game crashes on startup.

I hope someone knows how to fix this.

Link: [url:2hbp4me8]http://www.savefile.com/projects/808655567[/url:2hbp4me8]

edit:
Sorry, I forgot that the link does not go right to the file but to the project area. The file you want is "Private Variables Messed up".
I found and fix the loop problem. Thats when I found the Object/Sprite Private Variables problem.
File Link [url:2hbp4me8]http://www.savefile.com/files/1647496[/url:2hbp4me8]
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Fri Jul 04, 2008 2:24 pm

I dont see any "Main Layout" in the posted .cap.

So i can not help you with the variable.

But i do see other things in the posted .cap.

1/ the for each conditions in the key assignments are unneeded.
Why ?

Well, the compare private variable condition you have in the key binding events are Pick Conditions already. Every "Compare" condition is a Pick Condition, its a hidden LOOP already.

It works as follow.

It takes ALL the tanks. Loops trough them 1 by 1, hidden and in the background. It will test the private variable (in your case 'TankID'), if it meets the test conditions (in your case if 'TankID is equal to a number), it will feed that object to its Sub Events and Actions.

So when you compare ALL the tanks private variable TankID to the value 1. It takes all the tanks, and only the tank with TankID 1 gets picked out. Or what i call, gets picked from the group.
All sub events and conditions will only work on/with that picked tank.

What you now do is this.

The for each condition loops trough all 8 tanks, and the Compare condition loops trough all 8 tanks.
So what you do you could write as :

Loop from 1 to 8 (the for each loop)
_____if anything and nothing
_______ do nothing with tank(loopcounter)
_________Loop from 1 to 8 (the compare loop)
___________if 'TankID' = 1 -------------------------------------------> do actions and subevents
___________end if
_________end loop
_____end if
end loop

Each tank is passing 64 times a loop, where only 1 time is needed. At the end your game will lag.


2/ I see you still do not use containers. You do not have to. But it will make your live a lot more simple
B
3
S
2
G
4
Posts: 322
Reputation: 2,119

Post » Fri Jul 04, 2008 2:38 pm

Ashley,

Maybe you should rename all the "compare" conditions to something similar to:

Pick object with private variable ..

or

Find object with private variable
Find object with angle
Find object with opacity
Find object with colour filter
Find object with unique ID
Find object with X position
Find object with Y position
Find object with width
Find object with height

And it would be nice to have

Find object with behavior property
(compare behavior property)
B
3
S
2
G
4
Posts: 322
Reputation: 2,119

Post » Fri Jul 04, 2008 3:06 pm

Sorry, I forgot that the link does not go right to the file but to the project area. The file you want is "Private Variables Messed up".
I found and fix the loop problem. Thats when I found the Object/Sprite Private Variables problem.

In the "Main Layout" Object "tankbottom". The bad variable is "AngleToEnemy".

Edit:
File Link [url:5pzjpyz8]http://www.savefile.com/files/1647496[/url:5pzjpyz8]
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Fri Jul 04, 2008 4:22 pm

Hi TheInstance,
Thanks for your input on this. I have uploaded my latest Cap.

File Link [url:1dwrf3jw]http://www.savefile.com/files/1647496[/url:1dwrf3jw]
"Private Variables Messed up.zip"

I have fixed the tank numbering loop problem and I have taken out all the extra loop lines I did not need.

You can see the Private Variable problem when you run the game. Push F1 to pick a tank. The Hud info is wrong, and I know the code is right. This is what you get :

Laser:2
Shells:3
Fire:4
Landmines:0

But if you check the object/sprite "tankbottom" Private Variables you have this:

Laser:1
Shells:2
Fire:3
Landmines:4

The "AngleToEnemy" is bad and I can not delete it. It is not used in any code right now. But when I take it out the game crashes before it starts.

So If anyone knows how to take out the "AngleToEnemy" Private Variable in the object/sprite "tankbottom" and have the Cap not crash. I'll like to know.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sat Jul 05, 2008 3:55 am

I have Fixed this problem with the Object/Sprite Private Variables being Messed up. I just had to bite the bullet and re do the Object/Sprite . To bad it was my tank object and i had to redo about 80 to 90% of my code.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sun Jul 06, 2008 3:05 pm

Sowwy you had to re-code the .cap. I can attempt to give an explanation for the way the variables behave in your events. But Even then, the good solution would be: Re-code.

Its impossible to give a *concrete* and fulfilling explanation. I have an idea what happened. Or should i say "a feeling".

Allow me to start with pointing to the way Construct is reading and storing variables.
Take this as the illustration.

download/file.php?id=86

There are only 2 objects. RedOne and GreenOne.
Both are member of the family "Items"
Both have 2 private variables.
But ! Look at the private variables, and notice that they are not added in the same order.

In the RedOne, 'variable_1' is first. In GreenOne 'variable_2' is first added.

Or to translate this to what it really is about.

They are on different positions. In Redone 'variable_1' is at position 1 int the list of private variables. While its on position 2 in the GreenOne.

So what you say ? Well read the events sheet, its kinda straight forward.
It dont need explanation.

And yet, when you run it. You well see that Reading out the variables using a Family is not working as you expecting it would.

Reading the private variable by addressing the object with its Family name, will read out the private variable on position(x) in the list of private variables for that object. NOT by its name !!!!!!!

Do you see this ?

Now well when this is true for families. Its also true for reading out AND storing any private variable, how ever you address the object.

So what construct really does is this.
You make an event/action that reads/stores a private variable, and construct will translate the name of the private variable to a number representing its position in the list of private variables for that object. And make the calls by that number.

This is done on the moment you make the event/action.

Those calls to positions (in the events) will update if you change (in the layout) things in the private variables.

But at this moment, i hope due its still beta, you can force situations that will NOT update both, the positions the variable gets called by in the events AND the private variables as presented to you in the properties list in the layout editor.

Now funny, and thats always the same, those situations are usually forced by beginners like you and me. Because we trial and error more then advanced users.

Try this. Make an object with 3 variables. Use the 2nd and 3th variable in some events.
Then go back to the Layout editor.
Delete the 1st variable.
Realize that was wrong to do and press UNDO (CTRL+z)
The variable returns.
Now SAVE the .cap.
Then run it
And or enjoy a awful crash, or have a .cap with messed up variables.

Like this
download/file.php?id=87


Now how you trial ed and error d to come to the position you was in. I have no idea.
And, you must realize by now, that all traces to what exactly triggers the situation are gone.

Ashley, i hope you take that serious, even when its just coming from me.
B
3
S
2
G
4
Posts: 322
Reputation: 2,119

Post » Sun Jul 06, 2008 3:21 pm

Thanks TheInstance for taking a close look in to this.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sun Jul 06, 2008 8:28 pm

Thanks for the overview of the problem TheInstance I can really see how that would trip someone up! I'm sure if you report the problem with an attached CAP on the bug tracker that Ashley will fix it.
B
2
G
4
Posts: 57
Reputation: 1,164


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests