Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411491 Posts in 69377 Topics- by 58433 Members - Latest Member: graysonsolis

April 29, 2024, 04:24:31 PM

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



View Profile
« Reply #680 on: June 15, 2016, 11:31:15 AM »

I've been trying to look up how I smooth out input data.

I'm doing a starfox type of game and the analog input on the gamepad is a little noisy. I found some arduino and electronics related results when googling. In the tutorial I read about they simply set the current input value to the average of the last n values. I'm going to try this now but I thought I'd ask if anyone has any experience with this. I have my suspicions there might be a better way..
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #681 on: June 15, 2016, 12:32:49 PM »

A weighted average (with weight distributed more heavily toward the newest samples) is likely to feel better, and would give you plenty of knobs to tweak to get it just right.
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #682 on: June 15, 2016, 01:26:04 PM »

I think you are right. I just came to that conclusion too after trying a straight average. It did help but the problem is getting out of the center (0,0) has a lag equal to the size of the history.

I'll give the weighted average a shot now. Thanks!
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #683 on: June 15, 2016, 02:57:25 PM »

Weighted average definitely helped. Things are feeling a lot better now.  Thanks Smiley
Logged

Alessio
Level 0
***


Visual Artist


View Profile
« Reply #684 on: June 15, 2016, 03:07:42 PM »

I've an issue.
I'm using version 1.4.1757 free edition of Game Maker:Studio.

I have some questions:

Question 1: How do i actually reset a variable or perform a chunk of code or a whole script ONLY ONCE, without making it getting repeated every step? This would be really useful!

Question 2: Does "image_index" reset to 0 whenever i change sprite with "sprite_index"? Or do i have to reset it to 0 everytime?

Question 3 What's the "then" statement? I've found out about that but there is no mention of it in the docs. Seriously, what's that?

I'm not going to post any code because i'm not needing any solution to an issue i have. I just need info for better code management in the future.
Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #685 on: June 15, 2016, 03:15:43 PM »

I've an issue.
I'm using version 1.4.1757 free edition of Game Maker:Studio.

I have some questions:

Question 1: How do i actually reset a variable or perform a chunk of code or a whole script ONLY ONCE, without making it getting repeated every step? This would be really useful!

Question 2: Does "image_index" reset to 0 whenever i change sprite with "sprite_index"? Or do i have to reset it to 0 everytime?

Question 3 What's the "then" statement? I've found out about that but there is no mention of it in the docs. Seriously, what's that?

I'm not going to post any code because i'm not needing any solution to an issue i have. I just need info for better code management in the future.

1: I'm guessing you're referring to how when you use the keyboard_get() function it performs the action every frame that the key is pressed. All you need to do is use keyboard_get_pressed() instead, which will only return true on the first frame where you pressed the key. If it's not that then please provide further explanation because I have no idea what you mean!

2: You could easily verify this yourself by making a test program. Do it, it'll be good practice!

3: I have no idea lol. If I had to take a guess, I would say that it's an antiquated keyword for when if statements would work differently in previous versions of game maker.
Logged

Alessio
Level 0
***


Visual Artist


View Profile
« Reply #686 on: June 16, 2016, 01:45:39 AM »

1: I'm guessing you're referring to how when you use the keyboard_get() function it performs the action every frame that the key is pressed. All you need to do is use keyboard_get_pressed() instead, which will only return true on the first frame where you pressed the key. If it's not that then please provide further explanation because I have no idea what you mean!

2: You could easily verify this yourself by making a test program. Do it, it'll be good practice!

3: I have no idea lol. If I had to take a guess, I would say that it's an antiquated keyword for when if statements would work differently in previous versions of game maker.

1: No. By the way, in my code it was kinda like that, only with keyboard_check_released. This was when my sprite changed depending on buttons pressed. I've changed the code so my sprite changes only depending on the object's x speed. So the "keyboard_check_released" is useless now. That's why i was asking. Is there a kind of function or even a kind of event that does this? Because this would be super helpful even for moments when no key is actually pressed but only when there is a change of state. As soon as there is a state change i would set "image_index = 0" but this would perform the code forever and not only one step. Therefore, i would like to perform a code only once every time this code is called on.

2: I tried it but couldn't correctly verify: the "debug" tool for Game Maker doesn't let me the game into slow down mode. So that's why i was asking.

3: YoYo Games, by the way, has committed the wrongest move ever: removing old features and rendering Game Maker 8's project not very compatible with Game Maker: Studio. They should really document even the old commands, even if they are going to make better replacements.
I'm still waiting about the "then" statement anyway: knowing it may be useful anyway.
Logged
Polly
Level 6
*



View Profile
« Reply #687 on: June 16, 2016, 04:49:44 AM »

What's the "then" statement?

Then "then" keyword is a optional part of the if-statement.

Code:
if (<expression>) then <statement>

But because it's optional ( virtually ) nobody uses it Wink
Logged
Alessio
Level 0
***


Visual Artist


View Profile
« Reply #688 on: June 16, 2016, 02:15:57 PM »

That was one as short as clear reply. Thank you!    Hand Thumbs Up LeftSmileyHand Thumbs Up Right

I've still problems, though.

So i've found out that image_index doesn't indeed update everytime i change it (may depend from which event i use, though). I don't know why. That's why i decided to reset it. But how could i set a variable and make sure it's run only one step?

I've found out about a fantastic loop function: "for".
This will allow me to run a certain code under a certain condition. the number 30 in the conditional field is just for testing purposes. But i want it to be an actual minimal value, like 1, so the "image index=0" will be true only for that incredibly small time. This seems a great idea for me. the problem is...

the "for" loop refuses to run!!! Completely! And not only with this one.
This is my code in my Step event:
Code:
for (var animTimer=0 ; animTimer<30 ; animTimer++) {image_index = 0}

Yet, image_index stays at 0 every step... forever.

From Heartbeast's tutorials, there is this other code:
Code:
for ( var i=0 ; i<2 ; i++) {show_message (" Hi ");}

I direcly copied this from his tutorial and it is a correct code i believe. Even in his tutorials the code works. The "hi" popup will have to appear only two times (namely, two steps). Yet, the popup will appear every frame.

Seriously, why does this happen? Somehow my project file decided that "for" loop statements are crap Undecided
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #689 on: June 16, 2016, 02:24:53 PM »

I have the same problem with unity lool

Now all I have is while loop like

Code:
int i=0
while (i<max){
   somecode();
   i++;

}

Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #690 on: June 16, 2016, 02:26:01 PM »

If you want to run something only one step you're going to have to keep track of whether or not it has been run before, and then keep track of what conditions would reset that variable.

Also, that first "for" loop just sets your image_index to zero thirty times within one step. I don't know what you're trying to do but that's not how that's done.
Logged

Zorg
Level 9
****



View Profile
« Reply #691 on: June 16, 2016, 02:38:14 PM »

Does it make any difference if you use int instead of var?
Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #692 on: June 16, 2016, 02:41:26 PM »

"int" restricts your variable to being an integer, so if you try to set it to anything else it gives you an error. This is especially useful because all programmers are idiots (me included) and will eventually attempt to give a decimal value or a string to a variable that should remain an integer. This keyword simply guards against that. Hope the explanation helps!
Logged

Zorg
Level 9
****



View Profile
« Reply #693 on: June 16, 2016, 02:43:57 PM »

I was referring to the previous asked questions about loops. I'd use an integer in these cases (but i did not know why, exactly).

So thank you for your answer anyway. Smiley
Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #694 on: June 16, 2016, 02:44:53 PM »

Oops lol
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #695 on: June 16, 2016, 03:05:07 PM »

It's a comparison (bool) anyway, but good luck with i=2.0 and you have 2.0000000000001
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #696 on: June 16, 2016, 03:18:46 PM »

It's a comparison (bool) anyway, but good luck with i=2.0 and you have 2.0000000000001

That has happened to me lol

From Heartbeast's tutorials, there is this other code:
Code:
for ( var i=0 ; i<2 ; i++) {show_message (" Hi ");}

I direcly copied this from his tutorial and it is a correct code i believe. Even in his tutorials the code works. The "hi" popup will have to appear only two times (namely, two steps). Yet, the popup will appear every frame.

Seriously, why does this happen? Somehow my project file decided that "for" loop statements are crap Undecided

I think you misunderstand how the for statement works. Here's a link
Logged

Oats
Level 1
*


High starch content.


View Profile
« Reply #697 on: June 16, 2016, 06:05:53 PM »

you can fix that code by removing "var", then declare i somewhere else (it's been an age since I've used gm but I believe you put it in the init event to make it an instance wide variable).

also I don't think for loops do what you think they do as ProgramGamer said, try this code:

put this wherever you init instance variables (someone who's used GM since GM 7 should tell you)
Code:
int doThingXtimes = 0

then put this in your step
Code:
if (doThingXTimes > 0) { doThing() }
doThingXTimes--
then whenever you want this event to occur twice,
Code:
doThingXTImes = 2;

Logged

eh
Alessio
Level 0
***


Visual Artist


View Profile
« Reply #698 on: June 17, 2016, 02:10:48 AM »

Then i still not understand what's a "for" loop. From what i've got it's something that restrict an expression from being run as long as a condition is not met anymore. I pretty much understand about the "don't draw more balls in a row depending from "i" variable" thing, but in the tutorial i've read it's written that the "hi" message is meant to appear only two times. But it appears forever. I can't believe that what's written in the tutorial is wrong, but what's the actual problem then?

@Oats

That's what i was trying to do for hours in a row!
Yet it doesn't work i just don't get the reason.

First, why should i remove the "var"? It only delcares that a variable is local, within the event.
The "int variable = 0" in Game Maker: Studio should be put in the "Create" event.

Then i set the next chunk of code in the "Step" event.
The problem is that "doThingXTimes--" doesn't decrement "1" every step, does only subtract 1 to "doThingXTimes = 2"

Indeed the debug text i've put shows a fixed "1".

Why does that happen? Shouldn't it decrement until 0 instead of subtract only?

I understand the logic behind this but something is just missing.
« Last Edit: June 17, 2016, 02:20:25 AM by Alessio » Logged
Zorg
Level 9
****



View Profile
« Reply #699 on: June 17, 2016, 02:14:40 AM »

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

Edit: Also, don't put doThingXTimes = 2 in the frame loop, or it will loop forever, too. For example, put it on a key event like
Code:
if (keyboard_check_pressed(someKey)) { doThingXTimes = 2 }
« Last Edit: June 17, 2016, 02:22:58 AM by zorg » Logged
Pages: 1 ... 33 34 [35] 36 37 ... 69
Print
Jump to:  

Theme orange-lt created by panic