Lua - fast changing images - image

I'm not a programmer, even amateur, I just wanted a program that would change PSP screen (whole) color as fast as possible infinitely. I made something:
rdupa = Image.load("red.png")
gdupa = Image.load("green.png")
bdupa = Image.load("blue.png")
screen:clear()
while true do
screen:blit(0, 0, rdupa, false)
screen:clear()
screen:blit(0, 0, gdupa, false)
screen:clear()
screen:blit(0, 0, bdupa, false)
screen:clear()
end
Using Google, but that doesn't work. What did I do wrong (I have *.png images in the same folder as script)? Ready script would be seen veeeeeeery nicely.

I'm not sure about your environment but I'd guess it's most likely unable to update its main window or whatever as it's essentially stuck executing the Lua code snipped (unless that's executed in a separate thread).

Lua is a small and concise programming language and provides only few core functions (see this list).
Lua does not provide any functions to work with screen and images by default, so without knowing what library/framework are you using, there is little we can do to help.

For this answer, I'm operating under the assumption that you're using Lua Player (consider adding a luaplayer tag?). From what I can see in the documentation, you should be using
screen.flip()
instead of
screen:clear()
whenever you want to update the screen. Unfortunately, I do not have CFW on my PSP, so I cannot test this myself.

To be honest, I wouldn't even consider using images.
something like this would do :)
(This is using PGELua but can easily be adapted for LuaPlayer)
while pge.running() do
color = pge.gfx.createcolor(pge.math.rand(255),pge.math.rand(255),pge.math.rand(255))
pge.gfx.startdrawing()
pge.gfx.drawrect(0,0,480,272,color)
pge.gfx.enddrawing()
pge.gfx.swapbuffers()
end
if you want defined colours, maybe something like.
red = pge.gfx.createcolor(255,0,0)
gre = pge.gfx.createcolor(0,255,0)
blu = pge.gfx.createcolor(0,0,255)
loop = 1
while pge.running() do
pge.gfx.startdrawing()
if loop==1 then
pge.gfx.drawrect(0,0,480,272,red)
elseif loop==2 then
pge.gfx.drawrect(0,0,480,272,gre)
elseif loop==3 then
pge.gfx.drawrect(0,0,480,272,blu)
end
loop=loop+1
if loop>4 then
loop=1
end
pge.gfx.enddrawing()
pge.gfx.swapbuffers()
end

Related

Proximity prompt an image label change visible not working

I'm trying to make it so that when you use a proximity prompt an image label becomes visible but it's not working, how do I fix this?
local proximity = workspace.Cardpack.ProximityPrompt
local proximityPromptService = game.GetService("ProximityPromptService")
proximity.Triggered:Connect(function()
_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible
end)
You don't really need to use _G for this. Instead, we can directly declare it to the X1.
local prompt = workspace.Cardpack.ProximityPrompt
local x1 = workspace.Inventory.Frame.X1
prompt.Triggered:Connect(function()
x1.Visible = not x1.Visible
end)
_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible
This is where your script goes entirely wrong. This is not LUA syntax and is not how programming works. This is actually what you are currently trying to do.
local value = true = false;
Really what you should be doing is creating a reference to the ImageLabel you are trying to set. Then change it's properties. Setting a variable in the global enviroment won't change the ImageLabel's properties.
local ProximityPromptService = game.GetService("ProximityPromptService");
local ImageLabel = workspace.Inventory.Frame.X1;
local Proximity = workspace.Cardpack.ProximityPrompt;
proximity.Triggered:Connect(function()
ImageLabel.Visible = true;
end)
This seems to be a simple issue which can be solved with a simple solution (granted you know what you're doing). Now here's some things to note:
You don't need to use the ;'s you see on almost every line people make. It's not something mandatory and shouldn't be. Though it's good for when you want to have less lines (if it's your preference).
You wouldn't want to have 2 ='s on the same line as it's not the correct syntax (as #sl0th has stated), you cannot attempt such a task as it wouldn't even work. You want it to not just change it back to false anyways.
As you code this, I don't believe you fully understand how it works, and to make the code you first of all have to understand COMPLETELY or rather fluently how it works. So let's start off with that!
How do we do this? Let's see:
-- Perhaps put the script INSIDE of the Cardpack, and then do it from here.
-- Also, I'm not sure why you've put an "inventory.Frame" here, if it's a screengui then it should go in StarterGui, however if it's a billboardgui then please ignore me.
local Cardpack = script.Parent -- I've added it inside the cardpack as said.
local Prompt = Cardpack.ProximityPrompt
local Label = workspace.Inventory.Frame.X1 -- using the original directory as I don't know how your explorer looks.
local CanBeVisible = false -- if you want to toggle it.
Prompt.Triggered:Connect(function() -- make sure to look up on devforum about this.
if not CanbeVisible then -- "not CanBeVisible" is equivalent to "CanBeVisible==false".
CanBeVisible = true
Label.Visible = true
else -- if it's true and not false:
CanBeVisible = false
Label.Visible = false
end
end)
This is a more..."Acceptable" way of coding. People have their preferences, but this is generally how I'd do it based on how you did it. IF you don't understand much I'm always here to help, of course! :D
FINAL NOTES:
local A,B = "A", "B" -- you can assign multiple variables on a single line!
A,B = "B", "A" -- and you can also change more than one on the same line too.
local A = "A";print(A) -- that's how ; is used if you want to do more than one thing on the same line (but not done at the the same time on the same line!). ; Seperates the code without needing to add spaces, though adding/casting variables you should stick to using the comma(s) to separate them assigning new values and whatnot.
Also, you don't even need that ProximityPromptService variable as you never even use it! And you can't just do game.GetService(..), you IDEALLY do it as game:GetService(..).
I hope this helped you and if it did, mark this as the answer! Though this is my first time trying to help people I tried my best lol.

Reading REG_QWORD with VBScript?

I think the question speaks for itself. I have trouble getting some values out of the registry, and I was hoping someone around here might help me.
I'm stuck at IE9, as it is the only one which has some reasonable CSS capabilities, and does support GetObject().
So right now, lets say I'm trying to retrieve the memory size of a GPU at "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000\HardwareInformation.qwMemorySize" (as far as I know, this should be a universal path & key).
This is where the problem begins. Either I get no output, or some error saying something is different, or what (my system is running in a different language so I cant offer the right translation).
After some research, I seem to have found the issue - the value I'm trying to read is REG_QWORD, and unfortunately I was only able to find very little covering this topic, and most of the solutions did not work for me.
So right now, I am with this code, which, unsurprisingly, also does not work (the code I had since like the beginning):
for Each oItem in colGPUs
memory = oItem.AdapterRAM / 1048576
If memory < 0 Then
If InStr(oItem.Name, "NVIDIA") Then
Set wssx = CreateObject("WScript.Shell")
msgbox CStr(wssx.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\000" + GPUID + "\HardwareInformation.qwMemorySize"))
End If
End If
Unfortunatelly it seems like there is no direct way of retrieving the value - within HTA itself.
I was able to get the value, however I did it using Powershell, executed the command, set its output to a specific file and read it.
Anyways, here is the actual solution I came up with specifically for this issue
wshell.Run "powershell (Get-ItemPropertyValue 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000' 'HardwareInformation.qwMemorySize') | Out-File -FilePath C:\temp\gpu_mem.txt", 0, true
Set f = fso.OpenTextFile("C:\temp\gpu_mem.txt", 1, False, -1)
gpu_mem = CStr(f.ReadAll)
With this method Im directly obtaining the integer and passing it to the VBS

How to display debug info or console.log equivalent in Lua

I am creating many games using Lua and LOVE2D, but whenever I implement a new function and want to test it out, or simply want to know a value of a variable in Lua, I either display it on the game screen or just hope that it works.
Now my question is...
IS THERE A WAY TO DISPLAY SOME INFO, such as A VARIABLE VALUE or something else into the terminal or somewhere else? Just like console.log in javascript which displays some content in the javascript console in the browser. So, is there a way to do this is Lua?? using LOVE2D?
I am using a Mac, so I have a terminal and not a command prompt. Is there a way to display some content there? Anywhere else would also be fine, I just need to see if those values are as expected or not.
Use a conf.lua file to enable the console, then you should be able to use a standard print(). You can read the wiki entry here.
Note: You have to run Lua and Love2D via the terminal for this to work. Running Lua and Love2D like this is required for the print statements to show:
/Applications/love.app/Contents/MacOS/love "/Users/myuser/Desktop/love2d-test-proj"
You just need to add a conf.lua file to the same location where your main.lua. Your file may be as simple as this:
function love.conf(t)
t.console = true
end
But feel free to copy the whole configuration file from the above link and edit what you need.
I can't be completely sure about this, because I have no access to Mac, but the console is disabled by default and even on Windows, no prints are shown until you turn it on.
Alternatively You can also display debug info in the game itself like some games do.
What I like to do is add something like debugVariable = {} for logging events that happen in each loop and debugPermanent = {} for events that happen rarely. Possibly add convenience functions for writing to the variables:
function debugAddVariable(str)
table.insert(debugVariable, str)
end
--..and similarly for debugPermanent
Now a function to draw our debug info:
function debugDraw()
love.graphics.push() --remember graphics state
love.graphics.origin() --clear any previous transforms
love.graphics.setColor(--[[select color for debug info]])
love.graphics.setFont(--[[select font for debug info]])
for i, v in ipairs(debugPermanent) do
love.graphics.print(v)
love.graphics.translate(0, --[[fontHeight]])
end
for i, v in ipairs(debugVariable) do
love.graphics.print(v)
love.graphics.translate(0, --[[fontHeight]])
end
debugVariable = {} --clear debugVariable to prepare it for the next loop
love.graphics.pop() --recall graphics state
end
And we just call this draw function at the end of our love.draw() and the texts should appear.
Obviously, this method can be refined further and further almost infinitely, displaying specific variables, and adding graphs for some other variables to clarify the information you want to show, but that's kind of outside of the scope of the question.
Lastly Feel free to check here for debug libraries submitted by users.

AHK: Using RandomBezier Function

I'm trying to use RandomBezier.ahk (https://github.com/MasterFocus/AutoHotkey/tree/master/Functions/RandomBezier) to randomize the mouse path to click on things in game.
The Example.ahk in that github works for me, but when trying to use it in my own program, it doesn't work when calling the RandomBezier function.
I have the files in the same local directory.
Any help on getting this function to work?
Thanks
#SingleInstance force
#Include RandomBezier.ahk
^j::
screenWidth := A_ScreenWidth
screenHeight := A_ScreenHeight
//I'm using ratios so that I'm not hardcoding based on a given display resolution
Play_X := floor(0.02604*A_ScreenWidth)
Play_Y := floor(0.37037*A_ScreenHeight)
RandomBezier(0, 0, %Play_X%, %Play_Y%, "T1200 RO RD OT100 OB-100 OL0 OR0 P4-3") //<-- this line doesn't do anything. the mouse doesn't move.
;MouseMove, %Play_X%, %Play_Y%, 10 <--this line works, so I know that the variables Play_X, Play_Y works
Sleep 50
Click
This is a classic mistake of trying to use legacy syntax in a place where it doesn't belong (though I'd argue it no longer belongs anywhere whatsoever).
Function parameters are passed in as expressions, not as legacy text parameters.
So instead of legacy way of referencing a variable
RandomBezier(0, 0, %Play_X%, %Play_Y%,,
you do
RandomBezier(0, 0, Play_X, Play_Y,.
Overall I'd recommend you to try to to get rid of legacy syntax. It's not 2008 anymore.
Reading this page on the documentation is a good start to learning the difference
https://www.autohotkey.com/docs/Language.htm

Need to get information from Qt4ruby Form's textedit(textbox) and pass back to string for console

I think this problem is best described in code. I'm sure the solution is close, I just haven't been able to find it. I've been looking over the Qt4 api as well as doing tutorials. Here is my code so far:
require 'Qt4'
class PictureCommentForm < Qt::Widget
def initialize(parent = nil)
super()
#setFixedSize(300, 100)
#comment_text = nil
picture = Qt::Label.new()
image = Qt::Image.new('image.jpeg')
picture.pixmap = image
comment = Qt::LineEdit.new()
layout = Qt::VBoxLayout.new()
layout.addWidget(picture)
layout.addWidget(comment)
setLayout(layout)
connect(comment, SIGNAL('returnPressed()'), self, setCommentText(comment.text) )
end
def setCommentText(text)
#comment_text = text
$qApp.quit()
end
end
app = Qt::Application.new(ARGV)
comment_form = PictureCommentForm.new()
comment_form.show()
app.exec
comment_text = comment_form.comment_text
puts "Comment was:\n #{comment_text}"
EDIT: Thanks for that answer integer. All I want done is a dialog box showing a picture and comment so I can get that data. I do plan on making a full GUI version with qt4, but that's for later.
I don't know Ruby, so bear with me, but I use Qt extensively in Python.
First point is that Qt really, really doesn't want to be used the way you're trying to use it. If you're making some sort of script, then Qt wants you to give it to Qt so it can run your code when it feels like:
We recommend that you connect clean-up
code to the aboutToQuit() signal,
instead of putting it in your
application's main() function because
on some platforms the
QCoreApplication::exec() call may not
return.
Working with Qt you pretty much have to do event-driven programming and give it control of your program flow / main loop.
If you really just want some "utility" that shows some GUI input box and prints whatever the user inputs to console, consider putting the puts directly in whatever function you connected to the text box. Then you can use that program's output in other console scripts.

Resources