Author Topic: Lua Loop Defined By User  (Read 8039 times)

0 Members and 1 Guest are viewing this topic.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Lua Loop Defined By User
« Reply #15 on: May 31, 2011, 07:11:08 pm »
we have our WFRNG already for Lua. Are you going to port this to nspire lua?
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Ashbad

  • Guest
Re: Lua Loop Defined By User
« Reply #16 on: May 31, 2011, 07:14:44 pm »
Lua is a highly flexible language in many namable aspects, but when it comes to me writing condensing code "Ashbad-style" (AKA, as small as close as possible while still retaining meaning and without crossing the evil pink line in NetBeans Ruby) it's really picky, unfortunately :P

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Lua Loop Defined By User
« Reply #17 on: June 01, 2011, 02:46:12 am »
we have our WFRNG already for Lua. Are you going to port this to nspire lua?

This is not a WFRNG. This is a number guesser, in WFRNG there is no random number, it's the last one you choose.
« Last Edit: June 01, 2011, 02:46:32 am by Scout »

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Lua Loop Defined By User
« Reply #18 on: June 01, 2011, 04:42:26 am »
we have our WFRNG already for Lua. Are you going to port this to nspire lua?

This is not a WFRNG. This is a number guesser, in WFRNG there is no random number, it's the last one you choose.
No, WFRNG does generate random numbars (although 29 is quite common). The Lua version might be different, though...

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Lua Loop Defined By User
« Reply #19 on: June 01, 2011, 08:35:32 am »
Code: [Select]
--Program made by David Gomes

print("Enter number: ")
max_value = io.read("*number")           --Get maximum random number
if type(max_value) == "number" then      --If the user enters a number

  math.randomseed( os.time() )
  random_number = math.random(max_value) --Define a number
 
  counter = 0
 
  while true do
    print ("Guess a number: ")
    tried_number = io.read("*number")
    if type(tried_number) == "number" then
      if tried_number == random_number then
        print ("You Won")
        print (counter)
        break
      elseif tried_number > random_number then
        print ("Try a lower number")
        counter = counter + 1
      else
        print ("Try a higher number")
        counter = counter + 1
      end
    else
      print ("Not a number!")
    end
  end

else
  print("Not a number!")
  end

I actually thought that in a WFRNG, when counter=29, then it's right.

Here's a Lua program that is a number guesser, you win when you try the last option.

Example:

Code: [Select]
Max Value = 5
0
No
1
No
2
No
4
No
5
No
3
Yes

Code:

Code: [Select]
--Program made by David Gomes

print("Enter number: ")
max_value = io.read("*number")           --Get maximum random number
if type(max_value) == "number" then      --If the user enters a number

  math.randomseed( os.time() )
  random_number = math.random(max_value) --Define a number
 
  counter = 0
 
  while true do
    print ("Guess a number: ")
    tried_number = io.read("*number")
    if type(tried_number) == "number" then
      if counter<(max_value) then
        print ("Wrong Number")
        counter = counter + 1
      else
        print ("You won")
        break
      end
    else
      print ("Not a number!")
    end
  end

else
  print("Not a number!")
  end
« Last Edit: June 01, 2011, 08:38:30 am by Scout »

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Lua Loop Defined By User
« Reply #20 on: June 01, 2011, 10:41:53 am »
The thing with WFRNG on 8x calcs is that the inital RNG seed always produces 29. If you run some random stuff (and by that, I mean programs that use the RNG) before WFRNG, you probably won't get 29.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua Loop Defined By User
« Reply #21 on: June 02, 2011, 05:43:26 am »
Here is David's program ported to run on my nspire  ;D


Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Lua Loop Defined By User
« Reply #22 on: June 02, 2011, 08:24:33 am »
Yay, I still say its WFRNG
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y