Nested if statement in plantuml - plantuml

I am trying to do nested if statements in plantuml. Here's the code:
#startuml
start
:Search for File;
if(Is in local cache?) then (yes)
:Finish;
stop
else (no)
:Check Cached SearchObjectToNodeTb;
if(Find in SearchObjectToNodeTb) then (yes)
:Send refresh req. SO to SN;
else(No)
:Send SO query to closest SymbolToNodeCacheTb match;
if(Symbol in Table) then (yes)
switch(What role am I?)
case(SearchNode)
:Send out Query to SN and get SearchObject;
case(FileNode)
:Return results;
else(No)//can't find the if statement for here
switch(What role am I?)
case(client)
:Send to Node with closest result;
case(SearchNode)
:Perform alg. for tablesym. creation;
#enduml
It can't see the last if statement for the else. Is it possible to do nested if else statements in plantuml?

As far as I can see the endswitch (see e.g. https://plantuml.com/activity-diagram-beta) is missing the following works for me:
#startuml
start
:Search for File;
if(Is in local cache?) then (yes)
:Finish;
stop
else (no)
:Check Cached SearchObjectToNodeTb;
if(Find in SearchObjectToNodeTb) then (yes)
:Send refresh req. SO to SN;
else(No)
:Send SO query to closest SymbolToNodeCacheTb match;
if(Symbol in Table) then (yes)
switch(What role am I?)
case(SearchNode)
:Send out Query to SN and get SearchObject;
case(FileNode)
:Return results;
endswitch
else(No)
switch(What role am I?)
case(client)
:Send to Node with closest result;
case(SearchNode)
:Perform alg. for tablesym. creation;
endswitch
#enduml

Related

Is there a way to check if any content of a array is in another array in Roblox

So I am trying to make a script which allows me to ban people but the main script which checks if a player is in the game and in the banned users list to be killed or kicked. Here is my code:
local BannedUsers = {"littleBitsman"}
local Players = game.Players:GetChildren()
wait(10)
for index1,value1 in ipairs(Players) do
for index2,value2 in ipairs(BannedUsers) do
if Players[index1] == BannedUsers[tonumber(index2)] then
local HumanoidToKill = workspace[value1].Character:FindFirstChildWhichIsA("Humanoid")
if HumanoidToKill.Health >= 0 then
HumanoidToKill.Health = 0
print("killed " .. tostring(value1))
end
end
end
end
The wait(10) is so I can test the script without executing too early, and the use of my username is for testing.
Also when I do test it it does nothing at all.
You can use the table.find function.
local BannedUsers = {"littleBitsman"}
for _, player in ipairs(game.Players:GetChildren()) do
if table.find(BannedUsers, player.Name) then
player:Kick("You are banned!")
end
end

I want to list "user inputs" with using method

So i create a new class and i have a lot of objects in this class such as name, surname age etc.
But i am geting the same error everytime. And also i do not now how to list my arrays with using method.
Error: no implicit conversion of Array into String
def main
patients = []
puts "What do you want to do \nadd \nlist \nexit"
process = gets.chomp
if process == "add"
puts "Please enter patient's name"
patient1 = Patient_Covid_19.new()
patient1.Name = gets.chomp.to_s
patient1.Name << patients #error line
elsif process == "list"
#And i want to print the arrays(patients, ages, surnames etc.) in here but using a method.
elsif process == "exit"
puts "Have a nice day"
else
puts "Please enter add, list or exit"
main
end
end
main
Edit: It was small syntax mistake(error line). But i still need help for the list process.
You probably meant to do patients << patient1.Name.
You can loop over and print out attributes as follows:
patients.each do |patient|
puts "Name: #{patient.Name}, etc"
end
class Patient_Covid_19
attr_accessor :Ssn, :Name, :Surname, :Sex, :Age
end
def main
patients = []
puts "What do you want to do \nadd \nlist \nexit"
process = gets.chomp
if process == "add"
puts "Please enter patient's name"
patient1 = Patient_Covid_19.new()
patient1.Name = gets.chomp.to_s
patients << patient1.Name
main
elsif process == "list"
elsif process == "exit"
puts "Have a nice day"
else
puts "Please enter add, list or exit"
main
end
end
main
This is my code. When the user writes Add, he will enter the patient's information from the console and this information will be added to an array. When the user writes list, he/she will be able to see the information of the patients he has written before. I want to do the listing with a method.

Error message inside a loop - Pong game

I am making a game similar to pong in small basic. What I want to do is when the ball hits the wall the game ends and shows an error message.
What I did was use a while loop as such below:
While (hits right wall) or (hits left wall) or (hits top wall) or (hits bottom wall) = "True"
GraphicsWindow.ShowMessage("you lost", "game over")
Endwhile
What that actually does is keep repeating the error message and I have to quit the program. How can I get it to just show the message once when the conditions for it hitting either wall is true?
Use break once the condition is met and once you show the error message.
This is a job for a flag!
Before your loop you set a flag to true. Your loop is based on just that flag. Then for each exit condition that you need you have a separate if statement that handles that logic. When that condition is met, you set the flag to false.
This keeps the code simple, and the logic easy to follow.
Example:
gameOn = "true"
While gameOn = "true"
'Code to control your game
If (hitsLeftWall) Then
gameOn = "false"
ElseIf (hitsRightWall) then
gameOn = "false"
ElseIf (hitsLTopWall) then
gameOn = "false"
ElseIf (hitsBottomWall) then
gameOn = "false"
EndIf
EndWhile

repeating program (python)

Heyho
I want to repeat a program after runnning a task. At the start of the program I ask some questions, than the code jumps into the task. If the task is done the questions sholud ask again..
Each Question reads some infos at the serial port. If i get the infos ten times ich will restart the programm.. but the window closes and i must start the file..
What can i do?
import serial
import struct
import datetime
print("\n")
print("This tool reads the internal Bus ")
print("-----------------------------------------------------------------------")
COM=input("Check your COM Port an fill in with single semicolon (like: 'COM13' ): ")
ser = serial.Serial(
port=COM,
baudrate=19200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
print("\n")
print("Please choose an option: ")
print("Polling of measured values and the operating status (1)")
print("Reading Parameter memory (2)")
print("Reading Fault memory (3)")
print("EXIT (4)")
print("\n")
i=input("Reading: ")
while(i==1):
count=0
while (count<10):
print(file.name)
print(ser.isOpen())
print ("connected to: "+ ser.portstr)
data = "\xE1\x14\x75\x81"
ser.write(data)
a=(map(hex,map(ord,ser.read(46))))
with open("RS485_Reflex.txt",mode='a+') as file:
file.write(str(datetime.datetime.now()))
file.write(", Values: ,")
file.write(str(a))
file.write("\n")
print(a)
count=count+1
else:
i=0
loop=1
#-----------------------------------------------------------------------
while(i==2):
count=0
while (count<10):
print(file.name)
print(ser.isOpen())
print ("connected to: "+ ser.portstr)
data = "\xE1\x13\x00\x00\x74\x81"
ser.write(data)
a=(map(hex,map(ord,ser.read(11))))
with open("RS485_Reflex.txt",mode='a+') as file:
file.write(str(datetime.datetime.now()))
file.write(", Parameters: , ")
file.write(str(a))
file.write("\n")
print(a)
count=count+1
else:
i=0
#---------------------------------------------------------------------
while(i==3):
count=0
while (count<10):
print(file.name)
print(ser.isOpen())
print ("connected to: "+ ser.portstr)
data = "\xE1\x12\x00\x00\x73\x81"
ser.write(data)
a=(map(hex,map(ord,ser.read(11))))
with open("RS485_Reflex.txt",mode='a+') as file:
file.write(str(datetime.datetime.now()))
file.write(", Fault: , ")
file.write(str(a))
file.write("\n")
print(a)
count=count+1
else:
i=0
#----------------------------------------------------------------------
while(i==4):
file.close()
ser.close()
sys.exit(0)
file.close()
ser.close()
First, you should use If/Elif/Else statements instead of while loops.
while(i==1):
should be
if(i==1)0:
This is a simple program I wrote that you can follow:
# setup a simple run_Task method (prints number of times through the loop already)
def run_task(count):
print "Ran a certain 'task'", count,"times"
# count is a variable that will count the number of times we pass through a loop
count = 0
# loop through 10 times
while(count<10):
# ask questions
q1 = raw_input("What is your name?")
q2 = raw_input("What is your favorite color?")
# run a 'task'
run_task(count)

Retry loop until condition met

I am trying to navigate my mouse on object but I want to create a condition that will check if "surowiec" is still on the screen, if not I want to skip loop and go to another one. After it finish the second one get back to first and repeat.
[error] script [ Documents ] stopped with error in line 12 [error] FindFailed ( can not find surowiec.png in R[0,0 1920x1080]#S(0) )
w_lewo = Location(345,400)
w_prawo = Location(1570,400)
w_gore = Location(345,400)
w_dol = Location(345,400)
surowiec = "surowiec.png"
while surowiec:
if surowiec == surowiec:
exists("surowiec.png")
if exists != None:
click("surowiec.png")
wait(3)
exists("surowiec.png")
elif exists == None:
surowiec = None
click(w_prawo)
wait(8)
surowiec = surowiec
How about a small example:
while True:
if exists(surowiec):
print('A')
click(surowiec)
else:
print('B')
break
A while loop that is True will always run, until it it meets a break to exit the loop. Also have a look at the functions that are available in Sikuli, it can somethimes be hard to find them, that they are available. So here are a few nice ones:
Link: Link 1 and Pushing keys and Regions
The commands that I found myself very usefull are is exists and if not exists, and find that will allow to locate an image on the screen. Then you don't have to find an image over and over again if it stays on the same location. image1 = find(surowiec)

Resources