Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411613 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 10, 2024, 12:18:28 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 34 35 [36] 37 38 ... 69
Print
Author Topic: General thread for quick questions  (Read 136000 times)
Alessio
Level 0
***


Visual Artist


View Profile
« Reply #700 on: June 17, 2016, 02:24:54 AM »

If you display "hi" two times per frame it will be displayed forever, because that's a (for) loop in a (frame) loop.

Also, don't put doThingXTimes = 2 in the frame loop, or it will loop forever, too. Put it on a key event.

This isn't going to work.
Maybe before it did, i'm explaining it.

Since my character's frames were changing depending from the the keyboard pressed, i had simply to put "keyboard_check_released" to reset that variable. Now i've changed it so the sprite changes when x is set to 0. Therefore, this isn't going to work anymore. I'd just need to switch "image_index" to 0 only one step everytime a state is called. I can't believe this isn't possible in programming!

I've even tried the "begin step" even, but as soon as i use it my character just ignores gravity and flies away.
I don't get it.
« Last Edit: June 17, 2016, 02:41:05 AM by Alessio » Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #701 on: June 17, 2016, 03:07:57 AM »

I don't say this to insult or undermine you, but you seem to have a fundamental misunderstanding of how GameMaker:Studio works internally, which is causing you to make assumptions that are unfortunately false (like assuming that a for loop would restrict a piece of code to be run two time ever, when it actually runs it twice every frame). I recommend following beginner's tutorials so that you properly understand every basic aspect of GM:S before you can effectively put them together to create a game.

Hang in there, I've been through your struggle. Understanding how code works is not an easy task at first, but it is incredibly rewarding. You just have to work really hard to make some simple things work sometimes haha

Shaun Spalding is a really good tutorial writer. So good that he was picked up by YoyoGames (the folks who make GM:S) to be their community manager! I recommend checking out his stuff.

Oh, and do not despair. very little things are impossible in programming, you just need to figure out some obscure concepts before you can solve your problem Smiley
Logged

Oats
Level 1
*


High starch content.


View Profile
« Reply #702 on: June 17, 2016, 05:26:25 AM »

As programgamer said I think you need to go back and understand the structure of GM more, but to break a for loop down I'll try expressing it this way. A for loop is just wrapping around a while loop.
The for loop
Code:
for(var i = 0; i < 2; i++) {
   doThing()
}

is just a neater way of writing
Code:
 var i = 0
while (i < 20) {
  doThing();
  i++
}

They are functionally the same, someone just realised that since people use this pattern so often they might as well put it into one line.
For the sake of expressing myself I'm now just going to use the while loop to explain what's happening.
Ultimately, as you say, the purpose is to make a specific behaviour happen n number of times (in this case twice, but sometimes it's determined in other ways)
There are four things happening in the above code.
1. they have an expresion they want to do some number of times. The expression is whatever is inside the {}
2. they create a new local variable, by convention called i (for iteration I think), which holds how many times the loop has executed. It starts at 0 because when the variable is created the loop has executed 0 times.
3. the slightly more complex part, the while(condition). When a while loop is executed, it test the condition (the part between the ()), if the result is true, then the while loop executes the expression, in this case the expression is
Code:
{
doThing()
i++
}

Once it has finished executing the expression, it then retests the condition (it checks if i is still less then 2), if the condition is still true then it executes the expression again, then rechecks the condition, then executes the expression and so on, until the condition is false, where it stops and moves onto the line after the while loop. This is a pretty fundamental programmatic idea, so you should try and familiarise yourself with it, since you will use it a lot. As an interesting side note, if the condition never becomes true, as in the loop below
Code:
 while(true) {}
the while loop will never finish, and thus the program never moves on from it (I think after some amount of time GM realises it's stuck and throws an error).
4. (The easiest) to prevent our example loop from going forever, on the last line of the expression we add 1 to i (i++ is short for i = i + 1). So, because each time the expression is executed, i increases by 1, after 2 iterations of the loop i is no longer less than 2, and the loop ends having run the expression 2 times.

To bring this back to your problem, you need to realise that when you say
Code:
var i = 0
, the reason it runs twice every step event, is because i is being reset every step, thus the loop runs the expression twice every step. In fact if you reexamine your tutorial, it wasn't that the message was being shown two steps in a row, it was being shown twice in one step. I don't know the exact context of the tutorial, but it's reasonable to assert there must have been another control structure influencing it so that the for loop was only run once (but the for loop run the expression twice on that step). One easy solution would be to wrap the for loop in an if expression, like
Code:
if (doMakeMessages) {
  for(var i = 0; i < 2; i++) {
     doThing()
  }
  doMakeMessages = false
}
Then in whatever event you want to trigger the expression to occur twice, just set doMakeMessages to true. Important note, I do not create doMakeMessage in the above snippet. The code
Code:
 var doMakeMessages = true
if (doMakeMessages) {
  for(var i = 0; i < 2; i++) {
     doThing()
  }
  doMakeMessages = false
}
will have the exact problem you are encountering now, since doMakeMessages is being set as a local var every step, doMakeMessages will always be true at the time of the if statement checking it's condition, thus will always run the for loop.

I hope I've helped, again as said by ProgramGamer don't be discouraged, programming is totally different to anything else a human does, and feels counter intuitive to everyone when they begin, and sometimes feels counter intuitive to people who have been doing it for years. Just hang in, keep going through examples and tutorials and ask questions when you are stuck, and eventually you'll start understanding it. (Also frantically google searching often works).

edit: Jesus Christ I wrote a lot, I hope I helped?
Logged

eh
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #703 on: June 17, 2016, 07:08:05 AM »

and while is a fancy

i=0
label loop
if (i==max) jump end
code()
i++
jump loop
label end
Logged

Alessio
Level 0
***


Visual Artist


View Profile
« Reply #704 on: June 17, 2016, 07:34:45 AM »

Well, at least there is content to reply to.

Yeah, i don't understand GM:Studio's mechanics yet and the main problem is that i just don't know where to start. So i just started building something hoping to make something playable. I even can think in code, but not enough well, probably, since i lack so much knowledge.

Another thing that worries me is that when asking questions is too much. I mean, in some boards, in the past, i've seen beginners getting bashed, completely ignored or mislead because they kept asking question. Sometimes there is a ban for these "insistent" beginners. Sometimes, it even happened to me. Therefore, i'm even too reluctant asking very newbie questions because i've a lot of gaps.

Yet another thing that worries me is that i may get tutorial orders wrong. Can't deny there are a lot of video tutorial in the web but i prefer books or written resources much more (Mainly because english's not my first language and can't grasp properly spoken english). But i didn't hear a good opinion about GML books. And can't find too many written documentation.

That said, i have probably grapsed the problem with the loops. The way i'm writing them makes them run forever no matter what.
Funny because i totally understand the logic behind these: "something is true until a condition is met". The "for" is just a shorter way to write a more elaborate "while" loop! The problem is that i don't understand how to use them yet!

You are fairly experienced programmers so i believe so you may also believe the "i understand how that works but i actually don't, there is something i'm missing out" feeling. Because that's how i'm feeling.

I don't know, but so far my character car run, jump but nothing more. GML shouldn't be as hard as C++ and it's probably suitable for my needs. I'll lookup on more tutorials then but i still make this thing work. If i don't turn knowledge to skill i'm not going anywhere. One thing is sure: i need to know how to use the rest of the events but i can't find much written documentation.

Unfortunately i'm an idiotic artist. I'm an irrational douchebag who can't grasp math Sad Sad Sad
Logged
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #705 on: June 17, 2016, 12:29:30 PM »

Another thing that worries me is that when asking questions is too much. I mean, in some boards, in the past, i've seen beginners getting bashed, completely ignored or mislead because they kept asking question. Sometimes there is a ban for these "insistent" beginners. Sometimes, it even happened to me. Therefore, i'm even too reluctant asking very newbie questions because i've a lot of gaps.

As technical forum moderator, I wouldn't put up with anyone bashing someone for being a beginner, or posting deliberately misleading information (other than as an obvious joke, and even then it can be iffy). There isn't anything to do about getting ignored of course, though that can happen for a wide variety of reasons, so I wouldn't be too quick to assume it's due to beginner questions. As long as you show at least some effort to understand things, this shouldn't be a problem. Please continue asking questions so that we can assist you in understanding things!

This may be useful to read: https://www.mikeash.com/getting_answers.html
Logged

Alessio
Level 0
***


Visual Artist


View Profile
« Reply #706 on: June 27, 2016, 03:08:46 PM »

Anyway, after realizing that "step" in Game Maker is as long as one frame i also realized where i was going wrong. And i managed to do the thing Grin
I was so glad! But there was probably a better way, i'm not sure.

Anyway i'm checking tutorials right now and trying to build something in the process.
I'm stuck on something very peculiar, though.

I'm trying to do some gamepad controls.
But not the current Game Maker: Studio's ones. They look pretty easy to implement.

I'm talking about the legacy "joypad" controls. Since, currently, i don't own a natively supported Xbox gamepad for PC (i don't plan to get one for now, there is time) my current "Gamestop" controller (which looks like a PlayStation's controller) seems to only support the legacy Joypad buttons. Unfortunately the old joypad support seems to be very limited and require some coding to get it working like the normal keyboard check functions (they don't have "check_pressed" or "check_released" Shocked).
Unless you use something like JoyToKey, which isn't handy at all, i'm trying to find out how to use these functions but there is very little documentation. Also the help files aren't that "helpful".

So, do you know if there is one full tutorial that explains how to use joystick functions? The ones i've found are either incomplete or have missing links or files. But i may have missed something.

Logged
Polly
Level 6
*



View Profile
« Reply #707 on: June 27, 2016, 03:55:21 PM »

If you want released / pressed functions for legacy joysticks, you could do something along these lines ( for a single joystick ). Run the following script each step before anything else ...

Code:
global.buttons_previous = global.buttons_current;
global.buttons_current = 0;

for(i=0; i<4; i+=1) // Set the number of iterations to the number of buttons you want to support / check
{
    global.buttons_current += joystick_check_button(1, i+1) << i;
}

.. and then add the following two scripts and name them accordingly.

Code:
// joystick_check_button_pressed
mask = 1 << (argument0 - 1);
return (global.buttons_current & mask) && !(global.buttons_previous & mask);

Code:
// joystick_check_button_released
mask = 1 << (argument0 - 1);
return !(global.buttons_current & mask) && (global.buttons_previous & mask);

Then you can call joystick_check_button_pressed(numb) / joystick_check_button_released(numb) as you ( might have ) expected.
Logged
Alessio
Level 0
***


Visual Artist


View Profile
« Reply #708 on: June 28, 2016, 02:54:45 AM »

Can't really grasp bitwise operators.

I've never seen them very often so i'm not really sure how do they work. also the help file (again) isn't very helpful about it, i guess because it's not used very often. They only say it's "shift" but not sure what does that mean.

What do bitwise operators like "<<" mean?

I've also doubts about other legacy joypad functions as well, that's why i was asking if there was a "lost in the web" tutorial about it, since, today, new gamepad support seems to be in front page.
Logged
Polly
Level 6
*



View Profile
« Reply #709 on: June 28, 2016, 03:12:40 AM »

What do bitwise operators like "<<" mean?

It lets you shift the bits of a value. For example the value "6" is 0000110 in binary, which means that the 2nd and 3rd ( least-significant ) bits are set.



When you shift the bits of that number one position to the left ( using "<< 1" ), it becomes "12"



Take a look at this article on YoYoGames.

I've also doubts about other legacy joypad functions as well, that's why i was asking if there was a "lost in the web" tutorial about it, since, today, new gamepad support seems to be in front page.

Not sure what doubts you have regarding the "legacy" joystick functions .. they seem pretty straight-forward to me.
Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #710 on: June 28, 2016, 03:19:00 AM »

Ok, so the left and right bitwise shift operators are used to literally shift the bits of a variable in one direction or another. You may not know how variables work internally, so I'll explain a bit more in depth:

All variables are composed of bits, and a single bit can be represented as 0 and 1. And when you put multiple bits together, you can represent numbers by mapping them to each possible configuration of bits in the variable. Like this:

0010 is equivalent to 2

0110 is equivalent to 6

A four bit variable ranges from 0 to 15 because there are 16 different configurations for a 4 bit variable. And you can also increase and decrease the value of this variable sequentially.

0010(2) becomes 0011(3) when increased by one

0011(3) becomes 0100(4) when increased again

If you want to know more about bits and variables, you can google it and you will find many articles that explain all these things and more, way better than I could in this forum post. But, to get back to the bit shift operator

0010(2) << returns 0100(4) because the bits were shifted to the left.

0010(2) >> returns 0001(1) because, this time, the bits were shifted to the right.

Basically, they're divisions/multiplications by 2, but they also apply to some other non-number types, like characters. There aren't many practical uses for that though.

Hope this helps a bit Smiley
Logged

Alessio
Level 0
***


Visual Artist


View Profile
« Reply #711 on: June 28, 2016, 06:53:21 AM »

Yeah i've heard about binary and stuff like that, which is the total base of technologic devices. I guess every 4bit variable are used for hexadecimal calculation in almost every programming language (i say "almost" because GML, being more a scripting language made specifically for Game Maker, doesn't let users use hexadecimal values, but i may be wrong). I believe i've grapsed what the shift operators actually do. A bit like a train that scrolls (no pun intended, really, "binary" in Italy is also "railroad" but it's a totally different meaning, also "bi" = 2).

Well, i don't think i'll need to use bitwise operators at all when almost everything is automated with these game creation tools. Not to belittle programmers at all, since it's thanks to them we have game creation tools that let even creative artists create games with little to no actual programming experience. It's just that i don't believe them to be really necessary for a polished game. It may depend from inclination, i think.

I'll check anyway the article about binaries, since getting a little more background information never hurts.

The doubts i have about the legacy joystick functions is that i really don't know how some of these exactely they work.
the "joystick_check_button" is as it sounds: like the normal "keyboard_check".

But others are a little confusing, especially the "joystick_direction" one. It's said it uses the numeric pad on the right part of the keyboard as reference but looks just... weird. We already have a pair of functions for the first stick, a second pair for the second stick and another one for a third stick(which i don't have). Then we have the dpads, which are the directional buttons. What's "joystick_direction" for, then? Still, it's confusing.

Since i believe there is a lot to explain i asked if there was a tutorial. Some may be lost in the web, since now in front page we have the XInput ones and not the DirectImput anymore. Some have even missing links and are incomplete.
Logged
Polly
Level 6
*



View Profile
« Reply #712 on: June 28, 2016, 09:09:47 AM »

GML doesn't let users use hexadecimal values, but i may be wrong

You can use hexadecimals literals in Game Maker using the "$" prefix Wink

But others are a little confusing, especially the "joystick_direction" one.

The "joystick_direction" function maps the X and Y axis of the joystick to the virtual key-code of the corresponding numpad key. It's primarily intended as a easy-to-use built-in JoyToKey-esque helper function.
Logged
Alessio
Level 0
***


Visual Artist


View Profile
« Reply #713 on: June 28, 2016, 09:58:27 AM »

Oh yeah, i didn't remember about the "$" symbol. I knew you use the dollar symbol in ASM codes all time. I've been introduced to ASM time ago but never got into it. didn't know you could use that in Game Maker too but i don't see the point of it, from my point of view. But it's right to include pure programmer tools even into a scripting language very similar to a real programming language like GML.

Can't also see the point with "joystick_direction" at this point, if i already have PoV and analog sticks (and with "analog stick" disabled, the PoV buttons assume the role of left stick) but there must be a reason if they're there, probably for other kind of controllers. The problem is that that it as an approach of something like "if joystick_direction(0) = vk_numpad4" instead of a "joystick_direction(0, vk_numpad4)". So if i want to assign a variable from "if joystick_direction(0) = vk_numpad4" i don't really have idea how to do it if not doing "if joystick_direction(0) = vk_numpad4" then* kRight = true". I don't know if it's corret, though. It may be because anything like "if keyboard_check(ord('A'))" is equal to "if keyboard_check(ord('A')) = true" but i may have misinterpreted the function.
It's just because it's an hassle to write the same line of code every time.

Mmmh, i swear i've read from somewhere that they use DirectInput. They may have been incorrect. One thing is sure: my GameStop PC Advanced Controller doesn't use xInput. I may get an Xbox controller for PC after all, using it is surely less an hassle than the legacy joystick ones. The only thing is: how can i be sure i get an Xbox controller for PC that uses Xinput? Because, still from somewhere, i've read that some "Xbox" controllers don't work with Xinput... but that may be their mistake, not sure. Can't think why an Xbox controller doesn't work with its own native input engine.


*I've put this to make it little clearer for a one line code, but i know it's not necessary. I also try to express myself in the best possible way.
Logged
Polly
Level 6
*



View Profile
« Reply #714 on: June 28, 2016, 10:15:08 AM »

But it's right to include pure programmer tools even into a scripting language very similar to a real programming language like GML.

HTML / CSS and Photoshop support HEX as well. It's not all that uncommon.

I may get an Xbox controller for PC after all, using it is surely less an hassle than the legacy joystick ones.

I'd recommend using the "joystick" functions over the "gamepad" functions. Even if you need "gamepad" only features ( such as vibration ) include a "joystick" based fallback so people that don't have a XInput compatible controller aren't completely left out.

The only thing is: how can i be sure i get an Xbox controller for PC that uses Xinput?

Just make sure to get a official Microsoft Xbox ( 360 / One ) controller Wink
Logged
theomg
Level 0
*


View Profile
« Reply #715 on: June 28, 2016, 10:40:47 AM »

Shader question time!

I have a mesh of a bunch of non contiguous triangles that I move around using a vertex shader(Surface shader on Unity really).
How could I billboard each triangle if I don't have their center, as they're not separate objects?
Logged
Polly
Level 6
*



View Profile
« Reply #716 on: June 28, 2016, 10:54:42 AM »

I have a mesh of a bunch of non contiguous triangles that I move around using a vertex shader(Surface shader on Unity really).
How could I billboard each triangle if I don't have their center, as they're not separate objects?

If you're moving them around using a vertex shader, why not position all triangles around the 0,0,0 coordinate and offset your translation data by their original coordinates?
Logged
Alessio
Level 0
***


Visual Artist


View Profile
« Reply #717 on: June 28, 2016, 12:08:32 PM »

@Polly
Ah, so even Photoshop uses... well, that's obvious, if you want to script plugins and extensions for it. Bah, i'll stick with my Intuos 4 instead  Tongue
 
And well, I did not explain myself very good, i didn't mean to not use joystick functions at all but that i may put xInput gamepad as priority for now, if i get an Xbox gamepad for PC. I think the same, it's not fair to force players buy an Xbox gamepad if they don't own one.
In the while i'll try to figure out about these joypad things. I've found something anyway that could help me but if i have doubts i'll ask. Thanks for the time anyway Smiley
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #718 on: June 28, 2016, 02:00:32 PM »

To be frank hexadecimal is just a compact form of writing binary 4bit by 4 using a single character space instead of 4.

SO that 255 is not 11111111 but FF
Logged

Polly
Level 6
*



View Profile
« Reply #719 on: June 28, 2016, 03:29:30 PM »

Ah, so even Photoshop uses... well, that's obvious, if you want to script plugins and extensions for it.

I was actually primarily thinking of the hex notation in the color picker Smiley

Logged
Pages: 1 ... 34 35 [36] 37 38 ... 69
Print
Jump to:  

Theme orange-lt created by panic