help with a script

  • yousuck
    21st Feb 2017 Member 0 Permalink

    i want to make a script that generate random pixels of swch,metl,nscn,pscn but i dont know how to script...

    can anybody help me with the script please

    i got the idea when i was playing with swch and stuff

  • QuanTech
    22nd Feb 2017 Member 0 Permalink

    Let's say you wanna make a line of swch,metl,nscn,pscn from 100 x, 100 y to 100 x, 150 y:


    for y=100,150 do
    local rand = math.random(0,3)
    if rand==0 then tpt.create(100,y,56) end--SWCH
    if rand==1 then tpt.create(100,y,14) end--METL
    if rand==2 then tpt.create(100,y,36) end--NSCN
    if rand==3 then tpt.create(100,y,35) end--PSCN
    end

    Hope that helps


    EDIT: 2d version:
    for x=100,150 do
    for y=100,150 do
    local rand = math.random(0,3)
    if rand==0 then tpt.create(x,y,56) end--SWCH
    if rand==1 then tpt.create(x,y,14) end--METL
    if rand==2 then tpt.create(x,y,36) end--NSCN
    if rand==3 then tpt.create(x,y,35) end--PSCN
    end
    end

    (man, it's so hard to indent code in this amazing html editor here...)

    Edited 4 times by QuanTech. Last: 22nd Feb 2017
  • yousuck
    22nd Feb 2017 Member 0 Permalink

    thanks but i mean like have the pixels scatterd around, not just in a square

    you could add a varible "intensity" which defines the intensity of the random

    and i could change that to whatever i want

  • QuanTech
    22nd Feb 2017 Member 0 Permalink

    I don't think there's a way to control how randomly you can generate numbers in Lua. As for the scattering, this code plots the pixels all over the screen and also has empty spaces. If you do not want empty spaces, change "math.random(0,4)" to "math.random(1,4)":


    for x=4,607 do
    for y=4,379 do
    local rand = math.random(0,4)
    if rand==1 then tpt.create(x,y,56) end--SWCH
    if rand==2 then tpt.create(x,y,14) end--METL
    if rand==3 then tpt.create(x,y,36) end--NSCN
    if rand==4 then tpt.create(x,y,35) end--PSCN
    end
    end

    Guys, please tell me how to properly indent this code. The editor doesn't seem to like regular tabs ;-;

    Edited 2 times by QuanTech. Last: 22nd Feb 2017
  • yousuck
    22nd Feb 2017 Member 0 Permalink

    i tried and it didnt have enough spaces

    i want to have super scattering

    maybye i can edit the code and try

  • QuanTech
    22nd Feb 2017 Member 0 Permalink

    I was experimenting a bit more... and found a thing I think is slightly more random.


    function rando(x,m)
    local a = math.random(0,2^20)
    local b = math.random(0,2^20)
    x = (a*x+b)%m
    return x
    end
    rand = math.random() + math.random(0,4)
    for x=100,150 do
    for y=100,150 do
    rand = rando(rand,4.1)
    if 0.5<=rand and rand<=1 then tpt.create(x,y,56) end--SWCH
    if 1.5<=rand and rand<=2 then tpt.create(x,y,14) end--METL
    if 2.5<=rand and rand<=3 then tpt.create(x,y,36) end--NSCN
    if 3.5<=rand and rand<=4 then tpt.create(x,y,35) end--PSCN
    end
    end

    Edited once by QuanTech. Last: 22nd Feb 2017
  • jacob1
    22nd Feb 2017 Developer 0 Permalink
    @QuanTech (View Post)
    you know lua already has math.random ... right?
  • QuanTech
    22nd Feb 2017 Member 0 Permalink

    @jacob1 (View Post)

     yeah but math.random() doesn't seem random enough for his needs


    EDIT: I've compared the results of math.random() and my unnecessarily large script and my script seems to be a bit more random. yay

    Edited once by QuanTech. Last: 22nd Feb 2017
  • jacob1
    22nd Feb 2017 Developer 0 Permalink
    @QuanTech (View Post)
    I can guarantee it is random enough for whatever you need to do. If it doesn't appear random then you're just using it wrong.
  • yousuck
    22nd Feb 2017 Member 0 Permalink

    @QuanTech (View Post)

     thank you for the code..

    you must be a genius at lua