Trying to make a random speed generator [closed] - lua

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
Its on Roblox studio
Every 5 seconds the players speed changes
Im kind of new to coding
I tryed to use the math.random
I probably did it wrong
Tried to like use the output
I dont think it works like that
I do not know
PLEASE HELP

First insert a LocalScript in the PlayerGui then open the script for editing
in the scrpt type:
local MinimalSpeed = your minimal speed in numbers
local MaximalSpeed = your maximal speed in numbers
local LocalPlayer = game:GetService("Players").LocalPlayer
local Humanoid = LocalPlayer.Character:WaitForChild("Humanoid")
function makespeed()
Humanoid.WalkSpeed = math.random(MinimalSpeed,MaximalSpeed)
wait(5)
end
while true do
makespeed()
end
the default speed is 16 so type in what speed you want

Related

need help detecting game lighting in my lua script

I am trying to make a script, in Lua code, that detects the level of lighting in my game. I am pretty new to Lua so as far as I know lighting in the game is a number (2, 10, 5).
if game:GetService("Lighting").Brightness < 1 then
game.StarterGui.ScreenGui.output.Text = "You are getting cold";
end
I am not sure if it is just not detecting game:GetService("lighting").Brightness as a number or if the game does not know what game.StarterGui.ScreenGui.output.Text is. I've testing this multiple times, making small alteration every time, but most of the time I got no error. With the code now there is no error message.
Do not use game.StarterGui.
StarterGui is what gui is put inside a player's PlayerGui when they join. Players do NOT see StarterGui.
Instead:
game.Players.PlayerAdded:Connect(function(plr)
if game:GetService("Lighting").Brightness < 1 then
plr.PlayerGui.ScreenGui.output.Text = "You are getting cold";
end
end)
(player).PlayerGui is the gui the player sees. StarterGui will not auto update or modify the game's players' guis when it is changed.
If you have any more questions feel free to ask them with a comment! ^-^
Roblox lua documentation:
https://www.developer.roblox.com/en-us

Two pointers in ROM hardware implementation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
ROM is implemented by case statement to store fixed values in it and read them whenever we need.
But how can I read two values at the same clock cycle ??
It is always useful to show at least part of your code. I assume you have something like this:
case (adrs)
8'h00 : dout <= 8h01;
8'h01 : dout <= 8h03;
8'h02 : dout <= 8h07;
The only solution is to make two identical case statements but it is easier to instance the same ROM twice.
Alternative is to make a memory and initialise it.
reg [7:0] mem [0:255];
... // initialise memory e.g
... // using initial with for loop and case statement
always #(posedge clk)
begin
dout1< = mem[adrs1];
dout2< = mem[adrs2];
end
I assume this is for an FPGA so look at the vendor manual how to make a pre-loaded RAM. (Which is on fact a ROM as long as you don't write to it)

Random generator based off NStimer Xcode 7 swift 2 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want a function to be called at random times while the user is playing. For example after 2 seconds passed a function is called and then after another 6 seconds it is called again. How do I do that?
This is not working
func time() {
randomNumber = CGFloat((drand48())
timer = NSTimer.scheduledTimerWithTimeInterval(randomNumber, traget: self, selector: "startTimer", userInfo: nil, repeats: true)
Xcode is not liking it and I donot know why
Welcome to SO. This is not a site where you get other people to write your code for you. It's a site to ask for help with code you write yourself.
You want to use arc4random_uniform() to create a random number, and then scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: to fire your timer at a random time in the future.
Try that, and if you have problems, update your question with the code you're trying and tell us what happens with it.
Edit:
Here's a suggestion: log a few values of randomNumber. Are they small values? Those are a delay in seconds. If you are getting values of 1000, 1,000,000, or greater, it's going to take a while for your timer to fire.

What is ROBLOX Lua scripting? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I really dont understand what it really even is. Is it just normal scripting or something else?
Lua is a fairly well known and often embedded scripting language.
However, if you're after some basic "getting starting" information on Roblox scripting, check out the Roblox Wiki. (The tutorial's section would probably be of specific interest.)
Lua is a well known scripting and programming language that is lightweight and easy to learn. Many games have embedded it, including Garry's Mod (GMod) and World of Warcraft.
ROBLOX uses Lua to actually create games. Most of the features you see in ROBLOX (like the GUI and building tools) are actually coded in Lua.
I'd recommend seeing games by Anaminus, VolcanoINC and Telamon to see what you could do with Lua.
Lua is a scripting language somewhat similar to Java. Infact, I recall there being a Javalua blend as a scripting language in itself. Lua is probably the easiest scripting language to learn and work with. Its functions are fired by changes specified such as script.Parent.Value.Changed:connect(functionnamehere)
Parents are what the script or item specified is in.
Variables work like this:
v = script.Parent.Value
or
d = game.Workspace.ScriptFireValue.Value
If a ROBLOX Solo Game is the source and v's script.Parent's name (script.Parent.Name) is ScriptFireValue then v is equal to d.
The language also includes loops that are recognizable like
lua: while true do
vbs: do while/Loop
java: do while
'for' is a limited loop where it only loops for a certain amount of times.
exe.
for i = 1, 10 do
game.Lighting.TimeofDay = game.Lighting.TimeofDay + 1
end
This part of the script will run 10 times before passing on. when u have the part 1 - 10 or 1, 10.
The 'end' comes after anything highlighted in blue.
Things highlighted will be:
for [whatever's in here will not be highlighted] do - Both words only count for one end.
while true do
while [Something in here that exists or is a value] do - Both words only count for one end.
function()
if [something exists or is a value] then - Both words only count for one end.
else -- Used when the if statement before it is false. When used the 'if' and the 'else' count for one end.
elseif -- Used when the if statement before it is false but also calls for another if statement. When used the 'if' and the 'elseif' count for one end.
I think a few more.
Here's an example script I'm writing off the top of my head. The source I'm going off of is ROBLOX's Build/Edit mode in-game.
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends if
end -- ends for - do
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
That script if not obvious identified the player who clicked. (clicker). Btw the argument 'clicker' would be identified the cause of the function to be fired. So the cause is because a button was 'Clicked'. So 'clicker' retrieves the person who initiated that. Therefore identifying if the player is a certain person which would allow the process to continue. So if the player's name is coolboy10000 then it will gather all the players and kill them each.
To put a security on that button to where if the player is not coolboy10000 then the player will be killed you could do this:
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends for - do
else
clicker.Humanoid.Health = clicker.Humanoid.Health - 10000
end -- ends if and else
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
If there are multiple people to allow to do this function you could do:
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" or "coldnature" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends for - do
else
clicker.Humanoid.Health = clicker.Humanoid.Health - 10000
end -- ends if and else
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
Or if there is a specific person who should have a separate punishment:
function KillAllPlayers(clicker)
if clicker.Name == "coolboy10000" or "coldnature" then
people = game.Players:GetChildren()
for i = 1, #people do
people[i].Character.Humanoid.Health = people[i].Character.Humanoid.Health - 10000
end -- ends for - do
elseif clicker.Name == "Person299" then
clicker.Head.Position = clicker.Torso.Position
else
clicker.Humanoid.Health = clicker.Humanoid.Health - 10000
end -- ends if and else and elseif - then
end -- ends function
script.Parent.Clicked:connect(KillAllPlayers)
Yeah that's just the basics :/
There are tutorials out there. Mostly on ROBLOX free models. I say you should study some free scripts and learn how they work and stuff. This is just the basics. There is a tutorial on ROBLOX. Just search in Free Models scripting tutorials. Some dude wrote in scripts how to script. It's pretty long to read but that's how I learned.
Roblox is a gaming website where the users make the games using "Roblox Studio". It's almost like a super complex virtual Lego. To interact with your parts(anything in your game) you make scripts that are written in the language "Lua".
Roblox Lua is Lua 5.1 in Roblox's Data Model.
Roblox Lua Scripting is the act of writing in a script in Roblox Studio.
Their scripts are actually objects with embedded code inside of them. They're placed inside of roblox's basic data model and are used for creating and controlling objects, data, and therefore game-play.
I will not repeat what others have said, and say something else instead.
Unlike vanilla lua, ROBLOX lua (also known as rlua) is a modified version of lua.
ROBLOX has implemented different kinds of c and l closures such as tick, wait, delay, and so on, which is why it is a modified version of lua.
Roblox Lua scripting is an embedded coding language to add features to your game. It is easy to learn and is a loose interpretation of modern day game programming. Its an overall great language and I highly recommend it!
https://roblox.fandom.com/wiki/Project:Home
https://devforum.roblox.com/

What is a good Code to Test Ratio? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am using RSpec for writing tests.
What do you think, is a good Code to Test Ratio?
Code to Test Ratio is a bit of a misleading statistic. A much better method is to use rcov, you can easily use it by running rake spec:rcov
Whilst 100% code coverage is sometimes held up as an absolute target, you quickly run into the law of diminishing returns. Personally I aim for 90% code coverage in all production code; even though this is mainly arbitrary I find it much easier to have a target number to aim for.
A good test to code ratio is one that allows you to feel confident in the code you have written and also allows you to refactor with confidence you will know what you area ffecting in the rest of your application. I have had test ratios ranging from 1:1.5 to 1:2.5 or so, it can really vary depending the complexity of your application.
We're talking about opinions at the moment. A good code-to-test ratio is one where your code is covered to the extent that it needs to be to allow both confidence in what is written and confidence that, when you are refactoring, you will know what is breaking all around you.
Numbers are good, but putting too much stock in them can be just as dangerous.
My goal is no untested code revealed by rcov and heckle. When you get all the coverage you can get with rcov, then you can run the code through heckle. Heckle modifies your code and shows you which modifications were not caught by tests.
rspec knows about heckle. After installing the heckle gem: "spec foo_spec.rb -H Foo". Oh, and if you get a bizarre error, install version 1.2.2 of ruby2ruby instead of 1.2.4.
Here's heckle complaining about a function I thought I had fully specified:
The following mutations didn't cause test failures:
--- original
+++ mutation
def model_matches?(substring)
- s = substring.gsub(/\./, ".")
+ s = substring.gsub(/\033!\032\002l\}\?V\010d\}\r\-\fyg,a\*jFT\003_"ga\016\020ufN\0066/, ".")
s = substring.gsub(/\*/, ".*")
s = "^#{s}$"
Regexp.new(s, "i").=~(#model)
end
--- original
+++ mutation
def model_matches?(substring)
- s = substring.gsub(/\./, ".")
+ s = substring.gsub(/\./, "\023GA3w+h-#z$?I;a\"k0n^r$\005io#l\023H1M{\034m")
s = substring.gsub(/\*/, ".*")
s = "^#{s}$"
Regexp.new(s, "i").=~(#model)
end
--- original
+++ mutation
def model_matches?(substring)
- s = substring.gsub(/\./, ".")
+ s = nil
s = substring.gsub(/\*/, ".*")
s = "^#{s}$"
Regexp.new(s, "i").=~(#model)
end
--- original
+++ mutation
def model_matches?(substring)
s = substring.gsub(/\./, ".")
s = substring.gsub(/\*/, ".*")
s = "^#{s}$"
- Regexp.new(s, "i").=~(#model)
+ Regexp.new(s, "v\022").=~(#model)
end
How cool is that?
The only things I've found that are truly difficult to get full test coverage for are tests involving concurrency, esp. race conditions. Trying to prove that a mutex or a critical section must be in place can be difficult. Sometimes you can do it. Sometimes, you just have to shrug your shoulders, put in the line of code you don't know how to test, and move on.
It varies. Simple code I'd expect as much test code as production code. Complicated code can easily deserve twice as much test code. Do Test Driven Development and won't have to worry about the ratio since everything in the code was driven by a test and that is what is important.

Resources