• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with random numbers and using those random numbers

T

TurtleBitAlex

Guest
I'm trying to make a randomly generating item generator. that will make another item at that location that will repeat the same code but with different variables etc.
let's say that the object before it picked 3 (down)
So what it would do is

R1X= 3 //from before when the object before picked the down
R2E= pick a random direction(1,4)
if the number is not the same as the exit of the generator before it then does the following. if it's not then repeat
if direction = 1
make object at x+448
if direction =2
make object at y+448
if direction = 3
make object at x-448
if direction = 4
make object at y-448
Then after running through the generator it will get the R1X and the R2E and add them to a bigger string.
for example

R1X=4
It picks 4 as the R2E
As they are the same it repeats the code
Picks again and gets 2 as the R2E.
generates object at Y+448
Then gets Numbers 4 and 2 and adds them to the beginning of a string
42110101110110101011010101101010101110
so 42//Both combined\\ +string98(13131...).

Iv been trying to write a code but I just can't get my head around all the strings and everything
also all the r1x r81e R21x etc all have to be global so the other objects can use them. and all the numbers iv said will be changed.

Its really bugging me
Hope you can help even in any part of the code.
 

samspade

Member
I'm trying to make a randomly generating item generator. that will make another item at that location that will repeat the same code but with different variables etc.
let's say that the object before it picked 3 (down)
So what it would do is

R1X= 3 //from before when the object before picked the down
R2E= pick a random direction(1,4)
if the number is not the same as the exit of the generator before it then does the following. if it's not then repeat
if direction = 1
make object at x+448
if direction =2
make object at y+448
if direction = 3
make object at x-448
if direction = 4
make object at y-448
Then after running through the generator it will get the R1X and the R2E and add them to a bigger string.
for example

R1X=4
It picks 4 as the R2E
As they are the same it repeats the code
Picks again and gets 2 as the R2E.
generates object at Y+448
Then gets Numbers 4 and 2 and adds them to the beginning of a string
42110101110110101011010101101010101110
so 42//Both combined\\ +string98(13131...).

Iv been trying to write a code but I just can't get my head around all the strings and everything
also all the r1x r81e R21x etc all have to be global so the other objects can use them. and all the numbers iv said will be changed.

Its really bugging me
Hope you can help even in any part of the code.
I'm sorry, I've read both this post and the one that came before it, and I don't really know what you're trying to do. Two things would be helpful. Frist, using code brackets. Second, naming your variables something that is understandable. Third, saying not only what you're trying to do but why.

It sounds like you're trying to do the following things:
  • Randomly generate an item. (Not randomly create an item somewhere, but generate a completely new item).
  • Spawn that item somewhere (do you have that working?)
  • Store both a previous variable, and a new variable in the new item.
I think, though I'm not sure, that the first two things are working and what isn't working is the third. If you simple want the newly generated item to have both the variable of the old item and the new item then I would add it to an array or list.

Code:
///item create event
variable_array[0] = 0;

///something that creates an item
var original_item = /* something that will get the id of the first item you want the variable from */
with (instance_create(x, y, item)) {
    variable_array = original_item.variable_array;
    variable_array[array_length_1d(variable_array) + 1] = /* your number here */ ;
}
This code might not actually work exactly as done here because I'm doing this away from a computer I can test it on, but the basic idea is this. Inside the item have an array. Use that array to save the variables you want. When you create a new item, first find the item that you want the previous variable from and copy that items existing array. Then get the length of that array and put the new variable you want into it.

There are actually lots of ways to do the above, and the above might not be the best. I may have completely misunderstood what you want as well though.
 
A

altan0

Guest
I'm trying to make a randomly generating item generator. that will make another item at that location that will repeat the same code but with different variables etc.
let's say that the object before it picked 3 (down)
So what it would do is

R1X= 3 //from before when the object before picked the down
R2E= pick a random direction(1,4)
if the number is not the same as the exit of the generator before it then does the following. if it's not then repeat
if direction = 1
make object at x+448
if direction =2
make object at y+448
if direction = 3
make object at x-448
if direction = 4
make object at y-448
Then after running through the generator it will get the R1X and the R2E and add them to a bigger string.
for example

R1X=4
It picks 4 as the R2E
As they are the same it repeats the code
Picks again and gets 2 as the R2E.
generates object at Y+448
Then gets Numbers 4 and 2 and adds them to the beginning of a string
42110101110110101011010101101010101110
so 42//Both combined\\ +string98(13131...).

Iv been trying to write a code but I just can't get my head around all the strings and everything
also all the r1x r81e R21x etc all have to be global so the other objects can use them. and all the numbers iv said will be changed.

Its really bugging me
Hope you can help even in any part of the code.
I will try my best here because the sequence instruction you have provided is still vague at best. This is what I understand for now.
  • You are trying to generate a random number and this random number represents the item and the next location it will appear?
  • If the previous item is the same as the current generated number, then generate a new number again until it is different?
  • Then each time a number is generated and is different from the previous number, it will add to a long list of items that was made before?
Correct me if I am wrong because I want to know exactly what you want to do here.
 

TheouAegis

Member
You can figure this all out yourself as long as you know the basics of the answer you were given in the other thread.

Given three variables A, B and C, the fastest way to combine them is to multiply each successive value by 1 more than the max value of the preceding variable.

Given A=4, B = 2 and C = 57825647278 (the value you posted as a string but interpreted as a binary number), if the max value of A is 23 and the max value of B is 10, then you can create the value ABC by the formula V=(C*11+B)*24+A, resulting in a value of 15265970881444. Reversing the formula extracts the values of A, B and C such that A=V mod 24, B=V div 24 mod 11, and C=V div 11 div 24.

Or...

Given three numerical strings and/or reals A, B and C, you need to normalize the lengths of two of them so you can fetch them based on a specific length.

Given A=4, B=2, and C="110101110110101011010101101010101110", if the max number of places for A is 2 and the max number of places for B is 3, then the value ABC is created with V=string_format(string(A),2,0)+string_format(string(B),3,0)+C.
 
A

altan0

Guest
You can figure this all out yourself as long as you know the basics of the answer you were given in the other thread.

Given three variables A, B and C, the fastest way to combine them is to multiply each successive value by 1 more than the max value of the preceding variable.

Given A=4, B = 2 and C = 57825647278 (the value you posted as a string but interpreted as a binary number), if the max value of A is 23 and the max value of B is 10, then you can create the value ABC by the formula V=(C*11+B)*24+A, resulting in a value of 15265970881444. Reversing the formula extracts the values of A, B and C such that A=V mod 24, B=V div 24 mod 11, and C=V div 11 div 24.

Or...

Given three numerical strings and/or reals A, B and C, you need to normalize the lengths of two of them so you can fetch them based on a specific length.

Given A=4, B=2, and C="110101110110101011010101101010101110", if the max number of places for A is 2 and the max number of places for B is 3, then the value ABC is created with V=string_format(string(A),2,0)+string_format(string(B),3,0)+C.
Instead of combining values in a single variable, he could just use ds_list to sort out that problem. This way searching and storing for values is easier and organized. With lists, OP can even output the list as a single string or combination of values.

Instead of complicating things as it is, OP should find simpler solutions to his coding problems.
 
Top