Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411468 Posts in 69368 Topics- by 58422 Members - Latest Member: daffodil_dev

April 22, 2024, 10:39:44 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 52 53 [54] 55 56 ... 69
Print
Author Topic: General thread for quick questions  (Read 135257 times)
cynicalsandel
Level 7
**



View Profile
« Reply #1060 on: May 02, 2017, 07:13:30 AM »

hello, im a very bad/novice programmer

one of pico-8's demos uses this code

Code:
for i=1,5 do
  poke(rnd(0x8000),rnd(0x100))
end

for a glitchy effect. i know what the poke function does, and i know that the random values generated are what gives it the "glitchy" natures because it's literally just writing new values. my problem is i don't understand the first line. well, i know what it means. for all values of i that are from 1 to 5, it does the next line. however, the rest of the function doesn't ever call for i. so idk what it's really doing. i'm sure it's something simple and i'm just an idiot, but i've tried reading some stuff about for loops to try to help me understand, but i don't get it.

any help would be appreciated.
Logged

Polly
Level 6
*



View Profile
« Reply #1061 on: May 02, 2017, 07:55:16 AM »

my problem is i don't understand the first line. well, i know what it means. for all values of i that are from 1 to 5, it does the next line. however, the rest of the function doesn't ever call for i. so idk what it's really doing.

That snippet uses a numeric for-statement ( which is different from a generic for-statement ). A numeric for-statement uses 3 expressions .. the first is the initial value, second is the condition value ( when the variable is equal to this the program breaks out of the for-statement ), and the third is the increment value. Thing is .. the third expression is optional Smiley When it's absent a value of 1 is automatically used.
Logged
cynicalsandel
Level 7
**



View Profile
« Reply #1062 on: May 02, 2017, 08:53:27 AM »

thanks! i'm assuming it increments every frame (though idk for sure), but i understand the rest of it now.
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1063 on: May 02, 2017, 08:55:22 AM »

What it does is poking 5 random memory address, so the variable don't need to be used inside teh loop (random is different at each call hence 5 distinct memories). I guess it's poking in the range of the screen buffer. Just by looking at the number I guess the first parameter of poke is the address to write in and the second is the number to write (because 100 = 256 in decimal, and there is only 256 value in 8bits ... since it's call pico8...). I infer poking screen buffer because you say glitch effect, implying visual, so I guess the screen momery ranged from 0 to 0x8000 (32768 aka 2^15) but this seem too big lol so maybe it's generic glitching of teh whole game?
Logged

cynicalsandel
Level 7
**



View Profile
« Reply #1064 on: May 02, 2017, 08:58:34 AM »

yep, the first value is where you're sending it, and the second value is the new value to be written in i'm pretty sure
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1065 on: May 02, 2017, 09:04:31 AM »

I googled lol and it's corrupting at random teh whole memory ROFL, I guess some people want to see the world burn...
Logged

cynicalsandel
Level 7
**



View Profile
« Reply #1066 on: May 02, 2017, 09:09:29 AM »

yeah the only problem is since it's actually corrupting memory, you can't really undo it without rebooting. in that regard, fake glitches would work better, but i'm not really smart enough to know how to do that.
Logged

Polly
Level 6
*



View Profile
« Reply #1067 on: May 02, 2017, 09:16:29 AM »

yeah the only problem is since it's actually corrupting memory, you can't really undo it without rebooting.

Wrong, you can reload data from the cartridge into memory using the reload command Wink
Logged
cynicalsandel
Level 7
**



View Profile
« Reply #1068 on: May 02, 2017, 09:23:26 AM »

oh. thanks again. Wizard
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1069 on: May 02, 2017, 01:32:16 PM »

well for fake glitch limit it to teh range of the sound or screen buffer (or whatever visual system they have like sprite bank etc ...) I guess it would be something like [starting address] + rand([offset range]). There must be a wiki I'm too lazy to look up now lol. It will give random dots (increase iteration loop for more) on screen and dunno about sound really.
Logged

Photon
Level 4
****


View Profile
« Reply #1070 on: May 02, 2017, 02:22:34 PM »

What are your guys' opinions on finite state machines vs. behavior trees? Never really looked at the latter much before but seeing this topic spurred me into some research.

The primary difference to me seems to be in the control of logic flow. With FSM's, you define very concrete conditions and transitions between states; with behavior trees, you have a fairly linear logic flow but your conditional nodes can almost function as interrupts. An example of the latter that keeps coming to mind is of an action game boss that is hit mid-attack by a strong player attack: a conditional "no knockback" node could be the parent of whatever attack behavior tree is currently executing without having to know anything about the attack (or the attack knowing about the "no knockback" condition.) Contrast this with FSM, where I imagine you have to bake the "knockback" condition into each attack state.

The conclusion I'm drawing thus far is that FSM's are better for concrete, strictly-prioritized actions/states whereas behavior trees are good for situations where the state is more dynamic and/or in constant flux. That being said, they still seem rather similar to each other.
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1071 on: May 02, 2017, 02:32:34 PM »

Here is a thourough breakdown in video of teh difference between multiple technique compared to BT, made by a professional in teh industry (killzone AI).

http://aigamedev.com/open/article/behavior-trees-part1/

Logged

Eendhoorn
Level 6
*

Quak


View Profile
« Reply #1072 on: May 03, 2017, 03:43:42 PM »

I'm trying to limit how much my entity can turn it's directional vector

Current direction is the current directional vector of the entity.
Flock direction is the newly calculated directional vector of the entity.

if the difference between the current direction and the new direction is sharper than a X degree turn, then I want to set the directional vector to X.

I thought that using the dot product to check the change in direction is a good way, but I don't know how to actually use that value to clamp the direction :/

Code:
float maxTurnDot = 0.5f; //45 degrees
Vector2 currentDirection = rb.velocity.normalized();

//flock direction is calculated next direction vector
float dot = Vector2.Dot( currentDirection, flockDirection );
if( dot < maxTurnDot ){

    //set vector to max allowed turn angle
    //flockDirection = ???
    //flockDirection.Normalize();
}

Any ideas?
Logged

qMopey
Level 6
*


View Profile WWW
« Reply #1073 on: May 03, 2017, 06:13:04 PM »

Code:
float d = Dot( cur, desired );
if ( d < min ) d = min;
else if ( d > max ) d = max;
m2 r = Rot( d );
cur = Mul( r, cur );

Rot builds a rotation matrix (assuming 2D here), and Mul is doing a matrix multiplication with a 2D vector.
Logged
bateleur
Level 10
*****



View Profile
« Reply #1074 on: May 04, 2017, 07:01:42 AM »

qMopey's solution is mostly good, but does suffer from a problem which the original code also suffers from: dot product with the desired direction will give you the same result for both left and right angular deviation and consequently doesn't do what you want.

There are various solutions to this, but the simplest one is probably to dot product your local transform.right with the desired direction. Positive results then mean right turns and negative results mean left turns and the method works.

(I'm assuming this is Unity, but if not: transform.right is the vector 90 degrees clockwise from your facing.)
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1075 on: May 04, 2017, 01:32:10 PM »

I'm with bateleur, that's teh solution I use all the time (I nicknamed it the steer product ... XD )
Logged

TrisB
Level 0
*


View Profile
« Reply #1076 on: May 13, 2017, 12:54:40 PM »

Quick Gamemaker collision question:

Is there any way to alter (or at least control) the order in which collisions are checked? I have a player who can create platforms by throwing them horizontally, but depending on the order in which they're thrown, the vertical collisions for the player sometimes fails, and I think this is probably due to the order in which the code checks for those collisions.

Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #1077 on: May 13, 2017, 02:34:16 PM »

You can use the "before step" and "after step" events to check collisions either before or after everything in the step event. That should allow you to control the order of collisions enough for what you want to do.
Logged

Photon
Level 4
****


View Profile
« Reply #1078 on: May 19, 2017, 11:47:33 AM »

Does anyone still use the underscore naming convention over camel casing?

Just curious. I use underscores but nearly everything else I look at seems to be using camel casing. Shocked
Logged
qMopey
Level 6
*


View Profile WWW
« Reply #1079 on: May 19, 2017, 01:07:08 PM »

Yeah, I like underscores for type names and variable names. Functions LookLikeThisThough.
Logged
Pages: 1 ... 52 53 [54] 55 56 ... 69
Print
Jump to:  

Theme orange-lt created by panic