Unable to make schedule.do function and global variable work together - global

I want a few jobs executed everyday at specific times.
The first job I want to run is to acquire data from the database and store it in a global variable
The second job I want to run is a few minutes after the first job is executed where it uses the data acquired from the first job that was stored in a global variable.
global dataacq
dataacq = None
def condb():
global check
global dataacq
conn = psycopg2.connect(#someinformation)
cursor = conn.cursor()
query = "SELECT conversation_id FROM tablename"
cursor.execute(query)
dataacq = cursor.fetchall()
print(dataacq)
cursor.close()
conn.close()
check = True
print(check)
return dataacq
def printresult(result):
print(result)
schedule.every().day.at("08:59").do(condb)
schedule.every().day.at("09:00").do(printresult, dataacq)
Above is a part of the code I am using for testing. The problem here is when the "printresult" function is called it displays None as output. But if I execute all the functions without any scheduling then it works and displays what I need it to show. So why is this happening?

Related

ROBLOX INFINITE YIELD Infinite yield possible on 'Players.Aiman123boss.PlayerGui:WaitForChild("Main")'

i get this infinte yield:
Infinite yield possible on 'Players.Aiman123boss.PlayerGui:WaitForChild("Main")'
i want to fix it so heres my script:
local pg = player:WaitForChild("PlayerGui")
local Main = pg:WaitForChild("Main")
for i, v in pairs(Main.PetShop.ScrollingFrame:GetChildren()) do
if v.Name ~= "Template" and v:IsA("Frame") then
v.PetPrice.Text = game.ServerStorage:WaitForChild("Pets"):FindFirstChild(v.Name).Price.Value
v.PetName.Text = game.ServerStorage:WaitForChild("Pets"):FindFirstChild(v.Name).Name
end
end
You are waiting on the object "Main" here:
local Main = pg:WaitForChild("Main")
Roblox determined that it's possible that "Main" will never be found, because the object doesn't exist completely. Try checking your object hierarchy and determine if the following path exists:
game.StarterGui.Main
If it exists, check if there's any script that might destroy the GUI.

Value of my variables won't update on my script

i am making a simulator map when you have to refill your backpack
to refill my backpack i copy the value of the capacity of my backpack but if i change the value of the capacity of backpack variable, it won't refresh the value and give the first value.
local db = false
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if not db then
db =true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.data.Mail.Value = 0
plr.data.Mail.Value = plr.data.Backpack.Value
script.Parent.Sound:Play()
wait(1)
db = false
end
end
end)
thank you if you can help me !
plr.data.Backpack is not a variable, it is an object, you could name a variable an item you gave a value inside your script, such as "local db = false", this is a variable.
There is few ways of changing value in roblox, if you changed a value from your client while testing (debuging) changes won't appear, you would need to switch to server-side of current debug session in your roblox studio or use a server console to execute the code.
Try to debug by writing this into your event function somewhere in the end
local val = 243453543 --replace with some value
plr.data.Backpack.Value = val
if everything is correct you should see the value of 'val' variable as a value of plr.data.Backpack, you can check it in your explorer, there is also no needs to write plr.data.Mail.Value = 0 row because you are changing the value again without any other methods, values doesn't need to be cleared.
So in the end you should have:
local db = false
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if not db then
db =true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.data.Mail.Value = plr.data.Backpack.Value
script.Parent.Sound:Play()
wait(1)
local val = 243453543
plr.data.Backpack.Value = val
db = false
end
end
end)
Also check plr.data.Backpack.className is "NumberValue" in explorer.

Preventing Function Overriding in Lua Table

In my program when two functions with the same name are defined for the same table, I want my program to give an error. What's happening is that it's simply just calling the last function and executing it.
Here's a sample code
Class{'Cat'}
function Cat:meow( )
print("Meow!")
end
function Cat:meow()
print("Mmm")
end
kitty = Cat:create()
kitty:meow()
The result of the execution is only: "Mmm"
Instead I want something like an error message to be given.
Unfortunately, __newindex does not intercept assignments to fields which already exist. So the only way to do this is to keep Cat empty and store all its contents in a proxy table.
I don't know the nature of your OOP library, so you'll have to incorporate this example on your own:
local Cat_mt = {}
-- Hide the proxy table in closures.
do
local proxy = {}
function Cat_mt:__index(key)
return proxy[key]
end
function Cat_mt:__newindex(key, value)
if proxy[key] ~= nil then
error("Don't change that!")
end
proxy[key] = value
end
end
Cat = setmetatable({}, Cat_mt)

ABL inserting and displaying table data

I apologies for this being a very simple question but as a first time user of ABL open edge and im stuck. I have enter values into a table like so
METHOD PRIVATE VOID POPULATETABLE ( ):
DEFINE VARIABLE I AS INTEGER.
DO I = 0 TO 100:
CREATE TEST.
ASSIGN TEST.CUSTOMER_NAME="SMITH"
TEST.ORDER_NUMBER=I
TEST.ORDER="BOOKS"
TEST.COST=45.00
TEST.CUSTOMER_NAME = "JACKSON"
TEST.ORDER_NUMBER=I
TEST.ORDER="PAPER CLIPS"
TEST.COST=1.7.
ASSIGN TEST.CUSTOMER_NAME="JONES"
TEST.ORDER_NUMBER =I
TEST.ORDER="PENCILS"
TEST.COST=2.50
TEST.CUSTOMER_NAME = "TURNER"
TEST.ORDER_NUMBER = I
TEST.ORDER="PENS"
TEST.COST=0.7.
END.
END METHOD.
and I'm trying to display them using this
FOR EACH TEST:
DISPLAY TEST.COST TEST.CUSTOMER_NAME TEST.ORDER TEST.ORDER_NUMBER.
RETURN.
END.
However the result only shows the last row of data entered. can anyone help, I'm even unsure on whether the display function is right or the assign is.
The "return" in your FOR EACH is causing the code to leave the loop after the first record. Delete that statement and you'll see all the records.
FOR EACH TEST:
DISPLAY TEST.COST
TEST.CUSTOMER_NAME
TEST.ORDER
TEST.ORDER_NUMBER.
RETURN. /* this is why you're only seeing one record - */
/* get rid of this and you'll see all the records */
END.
I would avoid assigning an order# of 0. It's just asking to confuse people.
define variable i as integer no-undo.
do i = 1 to 100:
create test.
assign
test.order_number = i
test.customer = "smith" /* you need some way to get */
test.order = "books" /* actual data for the rest */
test.cost = random( 10, 100) /* of the fields... */
.
end.
And then review the orders with:
for each test no-lock:
display test.
end.
Yeah, all I needed was a create statement per each assign for each record and that worked. Thanks everyone, the working coded looks like:
CREATE TEST.
ASSIGN TEST.CUSTOMER_NAME="SMITH"
TEST.ORDER_NUMBER=I
TEST.ORDER="BOOKS"
TEST.COST=45.00.
CREATE TEST.
ASSIGN TEST.CUSTOMER_NAME = "TAYLOR"
TEST.ORDER_NUMBER=I
TEST.ORDER="PAPER CLIPS"
TEST.COST=1.7.
CREATE TEST.
ASSIGN TEST.CUSTOMER_NAME="THOMPSON"
TEST.ORDER_NUMBER =I
TEST.ORDER="PENCILS"
TEST.COST=2.50.
CREATE TEST.
ASSIGN TEST.CUSTOMER_NAME = "TURNER"
TEST.ORDER_NUMBER = 2
TEST.ORDER="PENS"
TEST.COST=0.7.
FOR EACH TEST WHERE TEST.COST > 1.3 BY TEST.ORDER_NUMBER:
DISPLAY TEST.
END.

In JDBC, how do I know when I am at the end of my FETCH?

I am following the example here
http://www.postgresql.org/docs/current/interactive/sql-fetch.html
And then looping the following command manually
FETCH FORWARD 5 FROM liahona;
in java. I have the above in an infinite loop and would like to know how I detect I'm at the end of the data set so I can break the loop
You get an empty result set when running FETCH FORWARD and you are at the end of the cursor's total result set. (This is described in slightly different words in the documentation.)
In use JDBC for this kind of SQL - it's for postgres command-line only.
For JDBC, you need something like this:
ResultSet rs = connection.createStatement().executeQuery("select * from mytable");
while(rs.next()) { // next() returns false if there are no more rows
int col1 = rs.getInt(1);
String col2 = rs.getString(2);
}