Roblox studio How do I change a TextLabel text in script - roblox

I want to make a gui that show your coordinates in game with text labels but my script seems didn't change the text at all
players = game.Players.LocalPlayer
players.CharacterAdded:Wait()
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text = script.Parent.Text
while true do
text = X..","..Y..","..Z
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
end
please help me
I wanted to change the text to XYZ position in string
but everytime i launch the game the text didnt change
and it still at default text in roblox ui text label

The simple answer to your question of how do I change a TextLabel text is you just set the Text property.
script.Parent.Text = "Hello World"
If you want a simple way to track the changing position of a player's character, I would recommend using the Changed signal on the Part. It will fire the connected function every time the property changes, and it allows you to avoid using an infinite while-loop.
local text = script.Parent
local player = game.Players.LocalPlayer
-- wait for the player's character to exist
if not player.Character then
player.CharacterAdded:Wait()
end
-- listen for changes to the player's position
local hrp = player.Character.HumanoidRootPart
hrp:GetPropertyChangedSignal("Position"):Connect(function()
local position = hrp.Position
local x, y, z = math.floor(position.X), math.floor(position.Y), math.floor(position.Z)
-- format the position, and display it in the TextLabel
local positionString = string.format("(%d, %d, %d)", x, y, z)
text.Text = positionString
end)

So I can see that you have made few mistakes here
Explanation:
First of all, players.CharacterAdded:Wait() doesn't always work and never works in studio. So instead of that, you should use players.Character:WaitForChild("HumanoidRootPart").
Second thing. By calling text = script.Parent.Text you were requesting the text inside of it (you were getting it as a string), so to simply fix that you have to use text = script.Parent and then when changing text you will have to use text.Text = "your text".
The next one is making your while loop infinite by using bool true. You can't make it like that or else the playar may experience lag or even script may crash. So I'd suggest to put this to something like wait(0.1).
And the last thing is that you should get X,Y,Z before putting it into the text or else it will be delayed.
And your final script should be looking like this:
players = game.Players.LocalPlayer
players.Character:WaitForChild("HumanoidRootPart")
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text = script.Parent
while wait(0.1) do
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text.Text = X..","..Y..","..Z
end
Keep scripting, nothing is easy without practice,
KubaDC

Related

PineScript - Keep in labels in the future when based on a fixed event

Thanks to the PineCoders on Twitter for pointing me in this direction.
I'm tracking both a hard stop (based on an entry indicator) and trailing stop and would like to keep them aligned.
bar_index+5 works great for the trailing stop, but for the hard stop, it simply places it 5 bars after entry indicator.
I've tried factoring in ta.barssince and it seems to have no effect, presumably since it believes the indicator is bar_index or something... I'm at a loss.
Here's the code:
SLAlabelText = str.tostring(SLCalc, "#.##")
var SLALabel = label.new(x = bar_index, y = SLCalc, color = color.red, style = label.style_none, textcolor = color.white, text=SLAlabelText)
if longBoy and stopLossA
label.set_xy(SLALabel, x = bar_index+5, y = SLCalc)
label.set_text(SLALabel, SLAlabelText)
label.set_tooltip(SLALabel, "Stop Loss: " + SLAlabelText)
"longBoy" is the indicator's confirmed state.
Chart image. Apologies for the meme stock, it was the best example.

how to make image tilt correction by user input in matlab

I am developing a semi user interface , in which I want to introduce a user input in which a popup window should come and asking that "do you want to tilt the image?" with yes or no option.
If I press yes again one window should open and ask me to put the required angle through which you want to rotate the figure. If I press no. program should proceed as before. I have tried like this but not working.
dlgTitle = 'Tilt correction?';
dlgQuestion = 'Do you wish to Tilt the image?';
choice = questdlg(dlgQuestion,dlgTitle,'Yes','No', 'Yes');
prompt={'Enter a value of \theta (in degrees)'};
name = 'Tilt correction';
defaultans = {'30'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
end
i am not sure if i am addressing the right problem, but if its "the proceed at no" issue you missed an "if"
dlgTitle = 'Tilt correction?';
dlgQuestion = 'Do you wish to Tilt the image?';
choice = questdlg(dlgQuestion,dlgTitle,'Yes','No', 'Yes');
if strcmp(choice,'Yes')
prompt={'Enter a value of \theta (in degrees)'};
name = 'Tilt correction';
defaultans = {'30'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
end
if you want to adress the [1,40] range as well you need an additional loop. but this should already work for just yes and no

How do i get the bounding rect of each word in a text (for reading eyetracking)?

For an eye tracking study i need the positions of each word in a text drawn to the window.
I can see how I can get the bounding box of the whole text as a return value using
[nx, ny, textbounds] = DrawFormattedText(win, tstring)
Is there a better way than drawing a whole sentence using this function word by word?
Something like this should do it:
teststr = {'Hello World!' ; 'How are you doing?'}
ystart = 100
xstart = 200
wordgap = 10
for i=1:size(teststr,1)
str=teststr{i};
wordlist = strsplit(str , ' ');
for j=1:size(wordlist)(1)
[nx, ny, textbounds]=DrawFormattedText(win, wordlist{j} ,xstart, ystart);
poslist{j} = textbounds;
xstart=nx+wordgap;
end
end
Not pretty, but it works. You will get problems if you have linebreaks.
EDIT: 2015-07-14: added wordgap suggestion from sven.io

World.QueryAABB giving incorrect results in libgdx

I'm trying to implement mouse selection for my game. When I QueryAABB it looks like it's treating objects much larger than they really are.
Here's what's going on in the image
The blue box is an actor containing a body that I'd like to select
The outline on the blue box is drawn by Box2DDebugRenderer
The mouse selects a region on the screen (white box), this is entirely graphical
The AABB is converted to meters and passed to QueryAABB
The callback was called for the blue box and turned it red
The green outline left behind is a separate body to check if my conversions were correct, this is not used for the actual selection process
It seems to be connected to my meter size, the larger it is, the more inaccurate the result is. At 1 meter = 1 pixel it works perfectly.
Meter conversions
val MetersToPixels = 160f
val PixelsToMeters = 1/MetersToPixels
def toMeters(n: Float) = n * PixelsToMeters
def toPixels(n: Float) = n * MetersToPixels
In the image I'm using MetersToPixels = 160f so the inaccuracy is more visible, but I really want MetersToPixels = 16f.
Relevant selection code
val x1 = selectPos.x
val y1 = selectPos.y
val x2 = getX
val y2 = getY + getHeight
val (l,r) =
if (x2 < x1)
(x2,x1)
else
(x1,x2)
val (b,t) =
if (y2 < y1)
(y2,y1)
else
(y1,y2)
world.QueryAABB(selectCallback, toMeters(l),toMeters(b), toMeters(r),toMeters(t))
This code is inside the act method of my CursorActor class. And selectPos represents the initial point where the use pressed down the left mouse button and getX and getY are Actor methods giving the current position. The next bit sorts them because they might be out of order. Then they are converted to meters because they are all in pixel units.
selectCallback: QueryCallback
override def reportFixture(fixture: Fixture): Boolean = {
fixture.getBody.getUserData match {
case selectable: Selectable =>
selected += selectable
true
case _ => true
}
}
Selectable is a trait that sets a boolean flag internally after the query which helps determines the color of the blue box. And selected is a mutable.HashSet[Selectable] defined inside of CursorActor.
Other things possibly worth noting
I'm new to libgdx and box2d.
The camera is scaled x2
My Box2DDebugRenderer uses the camera's combined matrix multiplied by MetersToPixels
From what I was able to gather, QueryAABB is naturally inaccurate for optimization. However, I've hit a roadblock with libgdx because it doesn't have any publicly visible function like b2testOverlap and from what I understand, there's no plan for there to be one any time soon.
I think my best solution would probably be to use jbox2d and pretend that libgdx's physics implementation doesn't exist.
Or as noone suggested I could add it to libgdx myself.
UPDATE
I decided to go with a simple solution of gathering the vertices from the fixture's shape and using com.badlogic.gdx.math.Intersector against the vertices of the selection. It works I guess. I may stop using QueryAABB all together if I decide to switch to using a sensor for the select box.

Controlling window position of a Powershell console

This works:
(Get-Host).UI.RawUI
$a = (Get-Host).UI.RawUI
$a.BackgroundColor = "white"
$a.ForegroundColor = "black"
$size = (Get-Host).UI.RawUI.WindowSize
$size.Width = 80
$size.Height = 30
(Get-Host).UI.RawUI.WindowSize = $size
But this doesn't work, and I am not sure how to make it work:
$position = (Get-Host).UI.RawUI.Windowposition
$position.X = 0
$position.Y = 30
(Get-Host).UI.RawUI.Windowposition = $position
The error I get is strange. It complains about "buffer" when I am trying to set external window position:
Exception setting "WindowPosition": "Cannot use the
specified Window X (column) position because it extends
past the width of the screen buffer. Specify another X
position, starting with 0 as the left most column of
the buffer.
The error is not really strange, because WindowPosition Gets and sets the position, in characters, of the view window relative to the screen buffer.
It does not set the position of the Window, but to put it crudely, the position in the buffer that you see through the view of the window. So in your case, you are getting the error because it is outside the buffer.
http://msdn.microsoft.com/en-us/library/system.management.automation.host.pshostrawuserinterface.windowposition%28v=vs.85%29.aspx
Unfortunately, setting the position of the window is not simple. There is a snapin for it though - http://wasp.codeplex.com/ ( use Set-WindowPosition)
Take a look at this script: Resize-Console.ps1 – Resize console window/buffer using arrow keys.
It is hopefully useful itself and partially should answer the question (the size part).