Math.random Help!

Started by mcgooey on Fri, 04/24/2015 - 15:43
Last seen on 22:29, 27. Nov 2017
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Math.random Help!
Fri, 04/24/2015 - 15:43

Hello,

I am  not sure if this is the correct  area to be posting this. I couldnt find a specific area to post. Here it goes.

I am trying to  create a block that updates. Once it hits its final stage within the update tick it is supposed to randomly place blocks withing the (I) and "K) access and the (-I) and (-K) access but i seem to get an error when trying to compile the mode when finished.

Here is what  I am using for the Math.random: only want things to spawn 3 blocks out from NEGATIVE and POSOTIVE access of "I" and "K"   Please help

j + (int)(Math.random()*1)+3
k + (int)(Math.random()*1)+3

j - (int)(Math.random()*1)+3
k - (int)(Math.random()*1)+3

 

Last seen on 22:29, 27. Nov 2017
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
in the J - (int)(Math.random(
Fri, 04/24/2015 - 15:49

in the J - (int)(Math.random()*1)+3 the "J" is an "I"

Last seen on 22:29, 27. Nov 2017
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
>:compileApiJava UP-TO-DATE
Fri, 04/24/2015 - 15:50

>:compileApiJava UP-TO-DATE
>:processApiResources UP-TO-DATE
>:apiClasses UP-TO-DATE
>:sourceMainJava
>C:\Pylo\MCreator155\forge\build\sources\java\mod\mcreator\mcreator_laurel8.java:163: error: no suitable method found for setBlock(int,int,int,Item,int,int)
>world.setBlock(i - (int)(Math.random()*1)+3 , j, k - (int)(Math.random()*1)+3, mcreator_laurelSeed.block, 0, 2);
> ^
> method World.setBlock(int,int,int,Block) is not applicable
> (actual and formal argument lists differ in length)
> method World.setBlock(int,int,int,Block,int,int) is not applicable
> (actual argument Item cannot be converted to Block by method invocation conversion)
>1 error
>:compileJava FAILED
The Error:
>FAILURE: Build failed with an exception.

>* What went wrong:
>Execution failed for task ':compileJava'.
>> Compilation failed; see the compiler error output for details.
>* Try:
>Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
>BUILD FAILED
>Total time: 20.681 secs
>C:\Pylo\MCreator155\forge>
>Task completed with return code 0 in 22451 milliseconds

Last seen on 14:26, 10. May 2015
Joined Apr 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
you have 2 extra "int" calls
Fri, 04/24/2015 - 19:51

you have 2 extra "int" calls in the

World.setBlock(int,int,int,Block,int,int)

remove the last 2 "int"s


World.setBlock(int,int,int,Block)

Last seen on 14:26, 10. May 2015
Joined Apr 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Plus reading further the
Fri, 04/24/2015 - 19:53

Plus reading further the Block you are calling is actually an item


(actual argument Item cannot be converted to Block by method invocation conversion)

Last seen on 22:29, 27. Nov 2017
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Plus reading further the
Fri, 04/24/2015 - 20:52

@#4 that fix the error but the placement is still not random it put it in the same spot.
iam not sure how to remove the init,init,init,init, unless it is pulling those from each add block i configure with the math.random.

here is what ive done so far

I chose "When Block added"

Add block, I input the math random code in "i" and "k"

I add 2 events one for positive on axis and Negative on axis

Positive:
i + (int)(Math.random()*1)+3
k + (int)(Math.random()*1)+3

Negative:
i - (int)(Math.random()*1)+3
k - (int)(Math.random()*1)+3

but somes to place in the same spot

Last seen on 14:26, 10. May 2015
Joined Apr 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
After some testing it out i
Fri, 04/24/2015 - 21:52

After some testing it out i discovered it is the *1

Positive:
i + (int)(Math.random()*1)+3
k + (int)(Math.random()*1)+3

Negative:
i - (int)(Math.random()*1)+3
k - (int)(Math.random()*1)+3

when i change *1 to *5

Positive:
i + (int)(Math.random()*5)+3
k + (int)(Math.random()*5)+3

Negative:
i - (int)(Math.random()*5)+3
k - (int)(Math.random()*5)+3

I got fully random results.

Last seen on 22:29, 27. Nov 2017
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:After some testing it out i
Sat, 04/25/2015 - 14:43

@#5 omg it works and ive created a monster :(
I also forgot to add to the (i + and k -) and (i - and k +)