Mac OSX Space Rocks Tutoriel

S

Sojourner

Guest
I have a few problems. I stopped at about 9:18 in the GameMaker DnD Attacking and Collisions video on YouTube. I don't know how to drag DnD boxes to the side, as they just snap back into position. When the bullet collides with an asteroid, it comes up with an error.

ERROR in
action number 1
of StepEventobj_asteroid
for object obj_bullet

Variable obj_bullet.spr not set before reading it.
 

Nidoking

Member
You're using a variable called "spr" in an object called "obj_bullet". You have not defined the spr variable in that instance of obj_bullet. Fix that.
 
S

Sojourner

Guest
First of all, thank you for the quick answer. I'm new to GameMaker and coding entirely. Where would I find the issue to fix it?

Apologies for the confusion on my part.
 

Nidoking

Member
You would find the issue in the obj_bullet, where you use a variable called spr. There is literally no further information that any person, alive or dead, can supply to you on the subject of this problem, because you have not provided enough information to give any more.
 
S

Sojourner

Guest
As I said, I'm very new to this. I don't know what information to supply.

I will try to fix it with your help. Thank you.
 

Nidoking

Member
If you provided the information about where you're using the spr variable in the obj_bullet, which is somewhere in the Step event for obj_asteroid, then I would be able to tell you where you're using the spr variable in the obj_bullet in the Step event for obj_asteroid. You're really going to have to meet me halfway here.
 
S

Sojourner

Guest
This is my first project on GameMaker, and I'm using the Space Rocks tutorial on YoYo Games' channel. I'd be entirely willing to communicate more information, I just don't know how.

Under my obj_asteroid's Step event is two things. There's a wraparound function and a rotation function, none of which have anything to do with the bullet.

The obj_bullet doesn't have a step event.

When the bullet hits an asteroid, it destroys itself and the asteroid, and creates two asteroids of a smaller size.


To be clear, I'm not frustrated with your help at all. Thanks for helping out even though I'm not the clearest.
 

Nidoking

Member
Show the wraparound function and the rotation function. Put them here in the forum. I'm asking for the bare minimum.
 

Slyddar

Member
You can right click on a blank area of the event and select "Live Preview", which takes you to a GML preview. You can then copy and paste all that code into the forum so we can see it. We can then help you.

Do this for the obj_bullet and also for obj_asteroid step event.
 

TheouAegis

Member
The error is inside objAsteroid.

In objAsteroid, if this is Drag&Drop, you have an action that targets objBullet which tries to read or modify a variable spr.

Odds are you either wanted to use spd or sprite_index instead. Go back and rewatch the tutorial regarding that part of your code.
 
S

Sojourner

Guest
This is under obj_asteroid.

// Wrap Around Room
move_wrap(1, 1, sprite_width/2);

// Set Instance Rotation
image_angle += 1;




This is under obj_bullet, when it collides with obj_asteroid

instance_destroy();

with(other) {

}

instance_destroy();

if(sprite_index == spr_astroid_huge)
{

}

repeat(2)
{

}

var newAstroid = instance_create_layer(x + 0, y + 0, "Instances", obj_astroid);

newAstroid.sprite_index = spr.spr_astroid_med;




Again, thank you all for your help.
 
S

Sojourner

Guest
Buddy, I've said multiple times that I've just begun to code, and yet you're surprised? It doesn't mean I'm any less grateful for your help, but a little less salt would be nice.
 

GMWolf

aka fel666
Buddy, I've said multiple times that I've just begun to code, and yet you're surprised? It doesn't mean I'm any less grateful for your help, but a little less salt would be nice.
You have just begun to code. That's understandable.
it sounds like you do not understand what a variable is.

However your code appears to make use of variables.
When following a tutorial, make sure you understand every single line.
Copying the code from a tutorial without understanding what every part does will lead you to nowhere.

I would suggest you go back over the tutorial and ensure you understand what each part does.
 
S

Sojourner

Guest
Rewatching the tutorials will probably do me good.

I do get quite lost in the coding jargon, though the tutorial I watched didn't clearly say what a variable was. I would like a clear explanation, and I'll probably find it somewhere.

Thanks!
 

Nidoking

Member
spr_astroid_huge
This is correct.

spr.spr_astroid_med
This is not. It's not Goofus and Gallant, but you'll have to show me the tutorial that tells you to put an additional spr. in front of the name of a sprite resource.

Buddy, I've said multiple times that I've just begun to code, and yet you're surprised?
Not in the least. There are a lot of people here who don't seem to want to have to do more than copy and paste and have everything working without understanding what they're doing. We have all only just begun. Excuses don't make games work properly. If it makes you feel better, that's your business. The people who will make games will learn from the tutorials, or the Manual, or other sources.

A variable is a symbol, meaning a collection of letters, numbers, and/or the underscore symbol, that represent a value that can change (vary) over the course of the program. They're used for storage and retrieval of information. They're the most basic piece of programming in any language. You get that one for free. Now you can read the Manual and understand it.
 
S

Sojourner

Guest
And that's where we're at a disconnect. I haven't copy and pasted, I've followed the directions to my best ability, which is why I've made mistakes. You're correct, excuses don't make games work properly. That's why I'm here, asking questions to help understand the problem.
 

GMWolf

aka fel666
A variable is a symbol, meaning a collection of letters, numbers, and/or the underscore symbol, that represent a value that can change (vary) over the course of the program. They're used for storage and retrieval of information.
Not super accurate.
An identifier is a collection of letters etc that represents a variables.

A variable is data that you can read or write to. It is represented in code by an identifier (a name).
The identifier and the variable is not the same thing: you could have multiple variables with the same identifier, depending on their scope.

Identifier + scope identifies a variable uniquely.

A variable can have local scope: this means it exists during the lifetime of a script/function, and is accessible from within that function.
Global scope means it lives for the entirety of the program, and is accessible from anywhere.
Instance scope means it is accessible through a particular instance, and lives for as long as the instance does.
 

Nidoking

Member
Not super accurate.
An identifier is a collection of letters etc that represents a variables.

A variable is data that you can read or write to. It is represented in code by an identifier (a name).
The identifier and the variable is not the same thing: you could have multiple variables with the same identifier, depending on their scope.

Identifier + scope identifies a variable uniquely.

A variable can have local scope: this means it exists during the lifetime of a script/function, and is accessible from within that function.
Global scope means it lives for the entirety of the program, and is accessible from anywhere.
Instance scope means it is accessible through a particular instance, and lives for as long as the instance does.
Yes, someone who can't figure out "delete spr." is going to find this amount of information useful. In case you can't tell, this is sarcasm.
 
S

Sojourner

Guest
You're correct, I don't understand it. However, you seem to be treating me as if I should automatically understand everything you say. To you, deleting a mistype is easy, laughable even. To me, I don't see where I'm going wrong. With time, this will improve. Treating me like an idiot does nothing for me or you.
 

Nidoking

Member
I tried talking to you like someone who is capable of learning concepts, understanding them, and applying that information to fix problems, but the thread has just gone farther and farther down the "I'm too new to learn, I can't understand anything" rabbit hole. Have you fixed the problem yet? I have, by now, explicitly told you exactly what you need to do. Understanding why you need to do it is something you'll have to handle on your own, because I can't implant concepts directly into your brain. If you're at that point, great, thread over. If not, then I suggest you stop asserting your newness and reread everything in the thread, because your solution is right there, then return to the previous sentence.

With time, this will improve.
I'll believe it when I see it. Like I said, I've seen a lot of people here of all levels of skill and experience who can't figure out simple concepts and don't seem to want to try. I expect that if I checked their post histories thoroughly, they'd all start with threads almost exactly like this one. You don't want to be like that. The answer to not understanding something is to do the research. Have you even searched for "variable" in the Manual? If you can't be bothered to do that, then why do you expect people on the forum to drop everything and come running to do your work for you? There's a reason lmgtfy.com exists, and it's not to be a first stop for search engines.
 
S

Sojourner

Guest
As I've repeatedly stated, I'm not too new to learn. However, it is harder for me to understand because I'm new. It's an explanation, not an excuse.

Yes, I fixed the problem, with your help. As you're willing to end the thread, I'm going to end as well.
 

Yal

šŸ§ *penguin noises*
GMC Elder
A bit counter-intuitively, the important part of the error is at the end:

Variable obj_bullet.spr not set before reading it.
(The lines above it tell you roughly where the error occurred, so once you have figured out what the problem is, you can go there to fix it)



One thing that's taking a lot of time to get used to as a programmer is that errors are a good thing. Because at least they tell you what's wrong, so it's easy to fix it (once you get a better understanding what the errors mean, at least). There's a lot of times where something works without causing an error, but it does the wrong thing. When that happens, you basically need to start looking without a clue for where to start, and it can be really time-consuming to fix the issue.
 
S

Sojourner

Guest
I've had a few errors since starting this thread, and they're getting easier and easier to solve. It's definitely a confidence booster ^^
 

Toque

Member
We all struggled at first no worries. A lot of times itā€™s a spelling error or code is in the wrong event.

sometimes I have to watch a tutorial three times to see where my error was.

Itā€™s really frustrating at first because you donā€™t know what the error means. How to fix it. Or if given the solution how to apply that advice. Lots of stumbling along....
 
S

Sojourner

Guest
All of the replies in this thread have given me confidence somehow, either by helping solve my problem or being moral support. Just wanted to say thanks to everyone who chipped in.
 
Top