I’m trying to connect to a webpage link using a Waveshare Sim7020 module through a Raspberry Pico, using https AT commands, but the connect command returns an error.
My final objective is to send a telegram message from it using a bot link for it like explained in https://core.telegram.org/bots/api#making-requests using this method:
https://api.telegram.org/bot\<token>/METHOD_NAME
This is not working for me, so thinking that maybe this is complex I’m trying to connect to google, bur the problem continues. I have also syncronized the time on the module with a server. I’m wondering that it could be a certificate problem? These are the functions used:
from machine import Pin, ADC
import os
import utime
import binascii
#import ujson
#print sys info
print(os.uname())
#using pin defined
ADC0= ADC(Pin(26))
sensor_temp = ADC(4)
led_pin =25 #onboard led
pwr_en = 14 #pin to control the power of sim7020x
uart_port = 0
uart_baute = 115200
APN = "cmnbiot"
i=0
reading=0
temperature=0
#indicate program started visually
led_onboard = machine.Pin(led_pin, machine.Pin.OUT)
def led_blink():
led_onboard.value(1)
utime.sleep(0.5)
led_onboard.value(0)
utime.sleep(0.5)
led_onboard.value(1)
utime.sleep(0.5)
led_onboard.value(0)
def hexStr_to_str(hex_str):
hex = hex_str.encode('utf-8')
str_bin = binascii.unhexlify(hex)
return str_bin.decode('utf-8')
def str_to_hexStr(string):
str_bin = string.encode('utf-8')
return binascii.hexlify(str_bin).decode('utf-8')
#power on the sim800c
def powerOn(pwr_en):
pwr_key = machine.Pin(pwr_en, machine.Pin.OUT)
pwr_key.value(1)
#power down the sim800c
def powerDown(pwr_en):
pwr_key = machine.Pin(pwr_en, machine.Pin.OUT)
pwr_key.value(0)
#2 sec timeout is arbitrarily chosen
def sendCMD_waitResp(cmd, timeout=2000):
print("CMD: " + cmd)
uart.write((cmd+'\r\n').encode())
waitResp(timeout)
print()
def waitResp(timeout=2000):
prvMills = utime.ticks_ms()
resp = b""
while (utime.ticks_ms()-prvMills)<timeout:
if uart.any():
resp = b"".join([resp, uart.read(1)])
print((resp).decode())
def sendCMD_waitRespLine(cmd, timeout=2000):
print("CMD: " + cmd)
uart.write((cmd+'\r\n').encode())
waitRespLine(timeout)
print()
def waitRespLine(timeout=2000):
prvMills = utime.ticks_ms()
while (utime.ticks_ms()-prvMills)<timeout:
if uart.any():
print((uart.readline()).decode())
#APN Manual configuration
def apnConfig(APN):
sendCMD_waitResp("AT+CFUN=0") #Disable RF
sendCMD_waitResp("AT*MCGDEFCONT=\"IP\",\""+ APN +"\"") #Set the APN manually
sendCMD_waitResp("AT+CFUN=1") #Enable RF
utime.sleep(1)
sendCMD_waitResp("AT+CGATT?") #Inquiry PS service
sendCMD_waitResp("AT+CGREG?")
sendCMD_waitResp("AT+CGCONTRDP") #Attached PS domain and got IP address automatically
Then this are the AT command tests and APN configuration:
#print uart info
uart = machine.UART(uart_port, uart_baute, bits=8, parity=None, stop=1)
print(uart)
#power on the board
powerOn(pwr_en)
#clear bufer in UART
waitResp()
#AT commands test
atCommandTest()
#APN Manual configuration
apnConfig(APN)
Then this is the time syncronization:
sendCMD_waitResp("AT+CSNTPSTART=\"[ntp.i2t.ehu.es](http://ntp.i2t.ehu.es/)\"")
sendCMD_waitResp("AT+CCLK?")
sendCMD_waitResp("AT+CSNTPSTOP")
sendCMD_waitResp("AT+CSNTPSTART=\"[ntp.i2t.ehu.es](http://ntp.i2t.ehu.es/)\",\"+01\"")
sendCMD_waitResp("AT+CCLK?")
sendCMD_waitResp("AT+CSNTPSTOP")
sendCMD_waitResp("AT+CURTC=1")
sendCMD_waitResp("AT+CRESET")
sendCMD_waitResp("AT+CURTC?")
sendCMD_waitResp("AT+CSNTPSTART=\"[ntp.i2t.ehu.es](http://ntp.i2t.ehu.es/)\"")
sendCMD_waitResp("AT+CCLK?")
sendCMD_waitResp("AT+CSNTPSTOP")
sendCMD_waitResp("AT+CURTC=1")
sendCMD_waitResp("AT+CURTC?")
sendCMD_waitResp("AT+CSNTPSTART=\"[ntp.i2t.ehu.es](http://ntp.i2t.ehu.es/)\",\"+01\"")
sendCMD_waitResp("AT+CCLK?")
sendCMD_waitResp("AT+CSNTPSTOP")
And this is the connection try out, where on create says OK but on connect says “ERROR”:
sendCMD_waitResp("AT+CHTTPCREATE=\"https://www.google.com/\"")
sendCMD_waitResp("AT+CHTTPCON=0")
sendCMD_waitRespLine("CAT+HTTPSEND=0,0,\"nextlink\"")
waitResp()
sendCMD_waitResp("CAT+HTTPDISCON=0")
sendCMD_waitResp("CAT+HTTPDESTROY=0")
Any ideas on what could be happening?
I am using scriptrunner postfunction and validator to perform 3 transitions back to back. The problem is that I receive an error message saying
[comment:Please, add a comment.] although a comment has actually been adde as you can see in the screenshot
Here is the code I have used, anyone knows how to fix this?
package CombineTransitions
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.Issue;
import org.apache.log4j.Logger
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.Issue;
import CombineTransitions.Configuration_CombineTransitions
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.event.type.EventDispatchOption
import java.util.concurrent.TimeUnit
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.Executors
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.workflow.WorkflowException
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.fields.screen.FieldScreenRenderLayoutItem;
import com.atlassian.jira.issue.fields.screen.FieldScreenRenderTab;
import com.atlassian.jira.issue.fields.screen.FieldScreenRenderer;
def log1 = Logger.getLogger("atlassian-jira.log")
def combineTransitionsHashMap= Configuration_CombineTransitions.getCombineTransitionsHashMap()
def issueStatusTypeId = combineTransitionsHashMap["issueStatusTypeId"] as String;
def transitionFromOpentoFixed = combineTransitionsHashMap["transitionFromOpentoFixed"] as Integer;
def transitionFromFixedToTested = combineTransitionsHashMap["transitionFromFixedToTested"] as Integer;
def transitionFromTestedToCompleted = combineTransitionsHashMap["transitionFromTestedToCompleted"] as Integer;
def fixedStatusName = combineTransitionsHashMap["fixedStatusName"] as String;
def testedStatusName = combineTransitionsHashMap["testedStatusName"] as String;
def completedStatusName = combineTransitionsHashMap["completedStatusName"] as String;
def fixedStatusId = combineTransitionsHashMap["fixedStatusId"] as String;
def testedStatusId = combineTransitionsHashMap["testedStatusId"] as String;
def completedStatusId = combineTransitionsHashMap["completedStatusId"] as String;
def errorMessage = combineTransitionsHashMap["errorMessage"] as String;
if (issue.getStatus().getSimpleStatus().getId().equals(issueStatusTypeId)) {
def ok = false
ok=performTransition(transitionFromOpentoFixed, fixedStatusName, fixedStatusId, errorMessage);
log.warn("MOUNA first boolean "+ok +" "+fixedStatusName)
if(ok){
ok= performTransition(transitionFromFixedToTested, testedStatusName, testedStatusId, errorMessage);
log.warn("MOUNA second boolean "+ok +" "+testedStatusName)
if(ok){
ok= performTransition(transitionFromTestedToCompleted, completedStatusName, completedStatusId, errorMessage);
log.warn("MOUNA third boolean "+ok +" "+completedStatusName)
}
}
}
def performTransition(int transitionToBeDone, String destinationStatus, String statusId , String errorMessage) {
log.warn("MOUNA ORIGINAL STATUS "+ issue.getStatus() + "DEST STATUS "+ destinationStatus)
//issue = ComponentAccessor.getIssueManager().getIssueObject(issue.id)
issue = transientVars.get("issue");
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String issueKey = issue.getKey()
IssueService issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("Transitioning issue from status "+ issue.getStatus().getName()+" to status "+ destinationStatus );
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
workflowTransitionUtil.setIssue(issue)
workflowTransitionUtil.setAction(transitionToBeDone)
//workflowTransitionUtil.addAdditionalInput(transientVars.get("comment"))
log.warn("MOUNA "+transientVars)
ErrorCollection errorCollection=workflowTransitionUtil.validate()
if (errorCollection.hasAnyErrors()) {
log.warn("MOUNA here 1 "+errorCollection.getErrorMessages().toString())
throw new InvalidInputException(errorCollection.getErrors().toString())
return false;
}else{
ErrorCollection progressErrorCollection=workflowTransitionUtil.progress()
if(progressErrorCollection.hasAnyErrors()){
log.warn("MOUNA here 2 "+progressErrorCollection.getErrors().toString())
throw new InvalidInputException(progressErrorCollection.getErrors().toString())
return true;
}else{
return true;
}
}
}
//#SuppressWarnings("rawtypes")
// Map getPopulatedFieldValuesHolder(WorkflowTransitionUtil workflowTransitionUtil, MutableIssue issue) throws Exception{
// Map fieldValuesHolder = new HashMap();
// FieldScreenRenderer fieldScreenRenderer = workflowTransitionUtil.getFieldScreenRenderer();
// for (FieldScreenRenderTab fieldScreenRenderTab in fieldScreenRenderer.getFieldScreenRenderTabs())
// for (FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem in fieldScreenRenderTab.getFieldScreenRenderLayoutItems())
// if (fieldScreenRenderLayoutItem.isShow(issue)) {
// fieldScreenRenderLayoutItem.populateFromIssue(fieldValuesHolder, issue);
// log.warn("fieldScreenRenderLayoutItem MOUNA "+fieldScreenRenderLayoutItem.getFieldScreenLayoutItem().getFieldScreenTab().getFieldScreen().getName())
// }
// return fieldValuesHolder;
// }
// String getError(String error){
// return error;
// }
I have an error message that is thrown when I try to execute a postfunction, the error message is:
org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.
You can see the error message in this screenshot:
In my code, I am using the line :
log.warn("MOUNA here 2 "+progressErrorCollection.getErrors().toString()) which is displaying a more meaninful message to the user which is: fixVersions:Fix Version/s is required. I would like to print this message instead to the user instead of org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.
How can I enforce this? I have tried using
UserMessageUtil.error(progressErrorCollection.getErrors().toString()) but it is not working. Anyone knows? Here is my code below:
package CombineTransitions
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.Issue;
import org.apache.log4j.Logger
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.Issue;
import CombineTransitions.Configuration_CombineTransitions
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.event.type.EventDispatchOption
import java.util.concurrent.TimeUnit
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.Executors
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.workflow.WorkflowException
def log1 = Logger.getLogger("atlassian-jira.log")
def combineTransitionsHashMap= Configuration_CombineTransitions.getCombineTransitionsHashMap()
def issueStatusTypeId = combineTransitionsHashMap["issueStatusTypeId"] as String;
def transitionFromOpentoFixed = combineTransitionsHashMap["transitionFromOpentoFixed"] as Integer;
def transitionFromFixedToTested = combineTransitionsHashMap["transitionFromFixedToTested"] as Integer;
def transitionFromTestedToCompleted = combineTransitionsHashMap["transitionFromTestedToCompleted"] as Integer;
def fixedStatusName = combineTransitionsHashMap["fixedStatusName"] as String;
def testedStatusName = combineTransitionsHashMap["testedStatusName"] as String;
def completedStatusName = combineTransitionsHashMap["completedStatusName"] as String;
def fixedStatusId = combineTransitionsHashMap["fixedStatusId"] as String;
def testedStatusId = combineTransitionsHashMap["testedStatusId"] as String;
def completedStatusId = combineTransitionsHashMap["completedStatusId"] as String;
if (issue.getStatus().getSimpleStatus().getId().equals(issueStatusTypeId)) {
def ok = false
ok=performTransition(transitionFromOpentoFixed, fixedStatusName, fixedStatusId);
log.warn("MOUNA first boolean "+ok +" "+fixedStatusName)
if(ok){
ok= performTransition(transitionFromFixedToTested, testedStatusName, testedStatusId);
log.warn("MOUNA second boolean "+ok +" "+testedStatusName)
if(ok){
ok= performTransition(transitionFromTestedToCompleted, completedStatusName, completedStatusId);
log.warn("MOUNA third boolean "+ok +" "+completedStatusName)
}
}
}
def performTransition(int transitionToBeDone, String destinationStatus, String statusId ) {
log.warn("MOUNA ORIGINAL STATUS "+ issue.getStatus() + "DEST STATUS "+ destinationStatus)
issue = ComponentAccessor.getIssueManager().getIssueObject(issue.id)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String issueKey = issue.getKey()
IssueService issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("Transitioning issue from status "+ issue.getStatus().getName()+" to status "+ destinationStatus );
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
workflowTransitionUtil.setIssue(issue)
workflowTransitionUtil.setAction(transitionToBeDone)
ErrorCollection errorCollection=workflowTransitionUtil.validate()
if (errorCollection.hasAnyErrors()) {
log.warn("MOUNA here 1 "+errorCollection.getErrorMessages().toString())
return false;
}else{
ErrorCollection progressErrorCollection=workflowTransitionUtil.progress()
if(progressErrorCollection.hasAnyErrors()){
log.warn("MOUNA here 2 "+progressErrorCollection.getErrors().toString())
// throw new WorkflowException(progressErrorCollection.getErrors().toString());
UserMessageUtil.error(progressErrorCollection.getErrors().toString())
return false;
}else{
return true;
}
}
}
I am using the pix2pix network provided on the TensorFlow website(https://www.tensorflow.org/tutorials/generative/pix2pix) and I want to have the result of the test set in every epoch to find out the model performance on my data. In this regard, I rewrote the fit function according to an example that exists in the guidance of tensorboard (https://www.tensorflow.org/tensorboard/get_started). It has 2 "for" loops in each epoch to train on the training dataset and then get the result on the test dataset but it takes too much time (1.5 hours) for ** every epoch** for mine. The data is included 540 images for the training dataset and 55 images for the test dataset, every image is of size 1600x1200. I put the related parts of the code below for more clarity. Other parts are the same as the original code except for the generator structure which is changed considering the size of images in the dataset.
I ran code on google Colab pro, with TPU and High Ram runtime.
Very thankful in advance for your response.
#tf.function
def train_step(input_image, target):
with tf.GradientTape() as gen_tape, tf.GradientTape() as disc_tape:
gen_output = generator(input_image, training=True)
disc_real_output = discriminator([input_image, target], training=True)
disc_generated_output = discriminator([input_image, gen_output], training=True)
gen_total_loss, gen_gan_loss, gen_l1_loss = generator_loss(disc_generated_output, gen_output, target)
disc_loss = discriminator_loss(disc_real_output, disc_generated_output)
generator_gradients = gen_tape.gradient(gen_total_loss,
generator.trainable_variables)
discriminator_gradients = disc_tape.gradient(disc_loss,
discriminator.trainable_variables)
generator_optimizer.apply_gradients(zip(generator_gradients,
generator.trainable_variables))
discriminator_optimizer.apply_gradients(zip(discriminator_gradients,
discriminator.trainable_variables))
return gen_total_loss, gen_gan_loss, gen_l1_loss, disc_loss
#tf.function
def test_step(input_image, target):
gen_output = generator(input_image)
disc_real_output = discriminator([input_image, target])
disc_generated_output = discriminator([input_image, gen_output])
gen_total_loss, gen_gan_loss, gen_l1_loss =
generator_loss(disc_generated_output, gen_output, target)
disc_loss = discriminator_loss(disc_real_output, disc_generated_output)
return gen_total_loss, gen_gan_loss, gen_l1_loss, disc_loss
EPOCHS = 5
for epoch in range(EPOCHS):
for (train_input_img, train_target_img) in train_dataset:
gen_total_train_loss, gen_gan_train_loss, gen_l1_train_loss, disc_train_loss = train_step(train_input_img, train_target_img)
with train_summary_writer.as_default():
tf.summary.scalar('gen_total_train_loss',gen_total_train_loss , step=epoch)
tf.summary.scalar('gen_gan_train_loss', gen_gan_train_loss, step=epoch)
tf.summary.scalar('gen_l1_train_loss', gen_l1_train_loss, step=epoch)
tf.summary.scalar('disc_train_loss', disc_train_loss, step=epoch)
for (test_input_img, test_target_img) in test_dataset:
gen_total_test_loss, gen_gan_test_loss, gen_l1_test_loss, disc_test_loss = test_step(test_input_img, test_target_img)
with test_summary_writer.as_default():
tf.summary.scalar('gen_total_test_loss',gen_total_test_loss , step=epoch)
tf.summary.scalar('gen_gan_test_loss', gen_gan_test_loss, step=epoch)
tf.summary.scalar('gen_l1_test_loss', gen_l1_test_loss, step=epoch)
tf.summary.scalar('disc_test_loss', disc_test_loss, step=epoch)
template = 'Epoch {}, gen_total_test_loss: {}, gen_gan_test_loss: {}, gen_l1_test_loss: {},disc_test_loss: {}'
print (template.format(epoch+1,gen_total_test_loss,gen_gan_test_loss,gen_l1_test_loss,disc_test_loss))
I tried to Experiment a bit with Objects in lua so I tried to make a StaticBody and a Collision and a Hitbox object but it spits out an error when I start the main in the line I create the staticbody: "main.lua:4 attempt to index global 'StaticBody' (a boolean value)"
https://pastebin.com/UFnEcYcT
here's the Code
--main.lua
StaticBody = require"StaticBody"
collision = require"collision"
player = StaticBody.StaticBody:new(300, 200, 40, 30, "RECT", 2000, 5000, 8.9, 900, 900, 5)
function love.load()
playerimg = love.graphics.newImage("player.png")
player:setSprite(playerimg, 1, 1, 0, 0)
end
function love.draw()
player:draw()
end
function love.update(d)
if love.keyboard.isDown("a") then
input = -1
end
if love.keyboard.isDown("d") then
input = 1
end
if not love.keyboard.isDown("a") and not love.keyboard.isDown("d") then
input = 0
end
player:update(d,input)
end
function love.keypressed( key, scancode, isrepeat)
if key == "space" then
player:jump(800)
end
end
-----------------------------------------------------------------------------------------------------------------
--StaticBody.lua
-----------------------------------------------------------------------------------------------------------------
StaticBody = {x = 0, y = 0, w = 1, h = 1, speedx = 0, speedy = 0, maxxspd = 1, maxyspd = 1, collosionmode = "RECT", sprite = nil, scalex = 1,
scaley = 1, offsetx = 0, offsety = 0, acc = 1, decel = 1, grav = 1, velx = 0, colbox = nil, hitbox = nil, turningfriction = 2}
collision = require"collision"
function clamp(variable,vmin,vmax)
if variable < vmin then
variable = vmin
end
if variable > vmax then
variable = vmax
end
end
function StaticBody:new(x, y, w, h, colmode, acc, decel, grav, maxxspd, maxyspd, turningfriction)
setmetatable({},StaticBody)
self.x = x
self.y = y
self.w = w
self.h = h
self.hitbox = collision.hitbox:new(x,y,w,h,false)
self.colbox = collision.ColObjekt:new(colmode,self.hitbox)
self.acc = acc
self.decel = decel
self.grav = grav
self.maxxspd = maxxspd
self.maxyspd = maxyspd
self.speedx = 0
self.speedy = 0
self.turningfriction = turningfriction
self.velx = 0
return self
end
function StaticBody:setSprite(sprite, scalex, scaley, offsetx, offsety)
self.sprite = sprite
self.scalex = scalex
self.scaley = scaley
self.offsetx = offsetx
self.offsety = offsety
end
function StaticBody:draw()
love.graphics.draw(self.sprite,self.x,self,y,0,self.scalex,self.scaley,self.offsetx,self.offsety,0,0)
end
function StaticBody:update(d,input)
local dir = 0
if input == -dir then
self.speedx = self.speedx / self.turningfriction
end
if input then
dir = input
end
if not self.colbox:getOnGround() then
self.speedy = self.speedy + self.grav * d
end
if input ~= 0 then
self.speedx = self.speedx + self.acc * d
else
self.speedx = self.speedx - self.decel * d
end
clamp(self.speedx,0,self.maxxspd)
clamp(self.speedy,0,self.maxyspd)
self.velx = self.speedx * d * dir
self.y = self.y + self.speedy * d
self.x = self.x + self.speedx * d * dir
end
function StaticBody:jump(jumpforce)
self.speedy = -jumpforce
end
------------------------------------------------------------------------------------------------
--collision.lua
------------------------------------------------------------------------------------------------
ColObjekts = {}
ColObjekt = {mode, x, y, w, h, collisionObjekts = ColObjekts}
--Constructer
function ColObjekt:new(mode,x,y,w,h,collisionObjekts)
setmetatable({},ColObjekt)
self.mode = mode
self.collisionObjekts = collisionObjekts
self.x = x
self.y = y
self.w = w
self.h = h
ColObjekts.push(self)
return self
end
--Constructer with Hitbbox
function ColObjekt:new(mode,Hb,collisionObjekts)
setmetatable({},ColObjekt)
self.mode = mode
self.collisionObjekts = collisionObjekts
self.x = Hb.x
self.y = Hb.y
self.w = Hb.w
self.h = Hb.h
end
function ColObjekt:setcolObjekts(colobs)
self.collisionObjekts = colobs
end
function ColObjekt:getColliding()
for key,i in pairs(self.collisionObjekts) do
if getCollidingWith(self,i) then
return true
end
return false
end
end
function ColObjekt:getCollidingWhich()
for key,i in pairs(self.collisionObjekts) do
if getCollidingWith(self,i) then
return true, i
end
return false
end
end
function ColObjekt:getCollidingDir(Colob1,Colob2)
if not getCollidingWith(Colob1,Colob2) then
return false
elseif Colob1.y > Colob2.y then return "ONTOP"
elseif Colob1.x < Colob2.x and Colob1.y > Colob2.y+Colob2.h then return "LEFT"
elseif Colob1.x > Colob2.x and Colob1.y > Colob2.y+Colob2.h then return "RIGHT"
else return "UNDER"
end
end
function ColObjekt:getOnGround()
if self:getCollidingDir(self,self:getCollidingWhich()) == "ONTOP" then
return true
else
return false
end
function getCollidingWith(Colob1,Colob2)
--if Colob1 == Rectangle
if Colob1.mode == "RECT" then
if Colob2.mode == "RECT" then
ColRect_Rect(Colob1,Colob2)
end
if Colob2.mode == "CIRCLE" then
ColRect_Circle(Colob2,Colob1)
end
end
--if Colob1 == Circle
if Colob1.mode == "CIRCLE" then
if Colob2.mode == "CIRCLE" then
ColCircle_Circle(Colob1,Colob2)
end
if Colob2.mode == "RECT" then
ColRect_Circle(Colob1,Colob2)
end
end
end
function ColRect_Edges(c,r)
--OBEN
if c.x > r.x and c.x < r.x + r.w
and c.y > r.y - c.h and c.y < r.y then return true
--UNTEN
elseif c.x > r.x and c.x < r.x + r.w
and c.y > r.y + r.h - c.h and c.y < r.y + r.h then return true
--LINKS
elseif c.y > r.y and c.y < r.y + r.h
and c.x > r.x - c.w and c.x < r.x then return true
--RECHTS
elseif c.y > r.y and c.y < r.y + r.h
and c.x > r.x + r.w - c.w and c.x < r.x + r.w then return true
--WENN NICHTS ZUTRIFFT
else return false end
end
function ColRect_Corners(c,r)
if math.sqrt((c.x - r.x * c.x - r.x) + (c.y - r.y * c.y - r.y)) < c.w/2 then
return true
elseif math.sqrt((c.x - (r.x + r.w) * c.x - (r.x + r.w)) + (c.y - r.y * c.y - r.y)) < c.w/2 then
return true
elseif math.sqrt((c.x - (r.x + r.w) * c.x - (r.x + r.w)) + (c.y - (r.y + r.h) * c.y - (r.y + r.h))) < c.w/2 then
return true
elseif math.sqrt((c.x - r.x * c.x - r.x) + (c.y - (r.y + r.h) * c.y - (r.y + r.h))) then
return true
else
return false
end
end
function ColRect_Rect(r1,r2)
if r1.x < r2.x + r2.w and r1.x > r2.x - r1.x and r1.y > r2.y - r1.h and r1.y < r2.y + r2.h then
return true
end
return false
end
function ColCircle_Circle(c1,c2)
local scndx = c1.x - c2.x
local scndy = c1.y - c2.y
if math.sqrt((scndx * scndx) + (scndy * scndy)) < c1.w/2 + c2.w/2 then
return true
end
return false
end
function ColRect_Circle(c,r)
if c.x > r.x and c.x < r.x + r.w
and c.y > r.y and c.y < r.y + r.h then
return true
end
if ColRect_Corners(c,r) then
return true
end
if ColRect_Edges(c,r) then
return true
end
return false
end
Hitbox = {x,y,w,h,show = false}
function Hitbox:new(x,y,w,h,show)
setmetatable({},Hitbox)
self.x = x
self.y = y
self.w = w
self.h = h
self.show = show
return self
end
function Hitbox:update()
if self.show then
love.graphics.Rectangle("fill",self.x,self.y,self.w,self.h)
end
end
function Hitbox:setVisible(b)
self.show = b
end
end
When you require a module in Lua, the value that is handed to you is the one that is returned at the very end of the module. In the absence of such a return statement, Lua seems to implicitly return a boolean (true or false) instead.
You need to return StaticBody at the end of StaticBody.lua. The same goes for every other module that your project interfaces with.
See this article for details.
As #nobody mentions in a comment, you can also decide what to export by assigning to the package.loaded table yourself.
package.loaded.StaticBody = StaticBody