Hey, i dont know to name my problem the right way, but i got a problem while using pengines.
This is my whole code so far. You can try it with swish
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Create sine table using Pengines</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"
type="text/javascript">
</script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script src="https://swish.swi-prolog.org/pengine/pengines.js"
type="text/javascript">
</script>
<script type="text/x-prolog">
/*Brand,Model,Cores,clockrate,onBoard-graphics(true,false),max-ram*/
processor(intel,'i3-3220',2,3300,true,32).
processor(intel,'i5-8400',6,4000,true,128).
processor(intel,'i7-8750H',6,4100,true,64).
processor(amd,'ryzen 5 3600',6,4200,false,128).
processor(intel,'i7-11850HE',8,4700,true,128).
processor(amd,'ryzen threadripper 3990X',64,4300,false,256).
/*brand,model,graphics memory*/
graphiccard(nvidia,'geforce gtx 1050',2).
graphiccard(nvidia,'geforce gtx 1050 ti', 4).
graphiccard(nvidia,'geforce rtx 2080',8).
graphiccard(nvidia,'geforce rtx 3080',10).
/*Games specs- (name,ram, graphic memory, needed space , cores, clockrate)
*/
game('cyberpunk 2077',12,6,70,4,4000).
game('valorant',4,4,8,4,3400).
game('warzone',12,6,175,6,3700).
game('gtav',8,2,72,4,3600).
game('minecraft',4,2,4,4,3900).
game('test',2,2,20,6,4200).
/*programs- (name,cores,clockrate, graphicmemory, ram, needed space*/
program('photoshop',2,2000,4,8,4).
program('after effects',4,3000,16,4,15).
program('premiere pro',8, 4000,16,4,8).
program('blender',4, 4000, 6, 16,0).
go :-
pengine_input("Gaming oder Office",Type),
(Type = 'Gaming'->
pengine_input("Gaming also, welche spiele?", Game1),
pengine_output(Game1),
game(Game1,A,Y1,B,X1,Z1),
graphiccard(V,W,Y2),
processor(Name,Model,X2,Z2,Grafik,Ram),
Y1 =< Y2, X1 =<X2, Z1=<Z2,
pengine_output("Unsere Empfehlung ist:"),
pengine_output(V),
pengine_output(W),
pengine_output("With:"),
pengine_output(Y1),
pengine_output(" GB Grafikspeicher"),
pengine_output("Und"),
pengine_output(Name),
pengine_output(Model);
Type='Office' -> pengine_input("Welche Programme",Programm1),
pengine_output(Programm1),
program(Programm1,Cores,Clock,Graph1,Ram,Space),
graphiccard(V,W,Graph2),Graph1 =< Graph2,
pengine_output("<b>Unsere emofehlung:</b> "),
pengine_output(V),
pengine_output(W)).
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
$('.js-example-basic-multiple').select2();
});
var buttonstep = 0;
var pengine = new Pengine({ server: "https://swish.swi-prolog.org/pengine",
ask:'go',
application: "swish",
onprompt:handlePrompt,
onoutput:handleOutput
});
/* Print pengine_input text X of "pengine_input(X, input)*/
function handlePrompt(){
$("#msg").html("<h1>" + this.data + "hhh" + "</h1>");
}
function handleOutput() {
if(this.data != "[object Object]"){
$('#answer').append(this.data + "<br/>");
}
}
function buttonclick(){
var o = $('.js-example-basic-multiple').select2('data')[0].text;
pengine.respond("'" + o + "'");
buttonstep++;
if(buttonstep==1 && o == "Gaming"){
var data = {
"games": [
{
id: 1,
text: 'gtav'
},
{
id:2,
text:'valorant'
}
],
}
$('.js-example-basic-multiple').empty().trigger('change');
for(var i = 0; i < data.games.length; i++) {
var text = data.games[i].text;
var id = data.games[i].id;
var newOption = new Option(text,id,false,false);
$('.js-example-basic-multiple').append(newOption).trigger('change');
}
}
else if (buttonstep == 1 && o == "Office"){
console.log("office");
var data = {
"programs": [
{
id: 1,
text: 'photoshop'
},
{
id:2,
text:'blender'
}
],
}
$('.js-example-basic-multiple').empty().trigger('change');
for(var i = 0; i < data.programs.length; i++) {
var text = data.programs[i].text;
var id = data.programs[i].id;
var newOption = new Option(text,id,false,false);
$('.js-example-basic-multiple').append(newOption).trigger('change');
}
}
}
</script>
</head>
<body>
<div id="out">
<select class="js-example-basic-multiple" name="games[]" multiple="multiple" style="width:300px">
<option value="Office">Office</option>
<option value="Gaming">Gaming</option>
</select>
<button onclick="buttonclick()">click</button>
</div>
<div id="msg">
</div>
<div id="answer"></div>
</body>
</html>
My problem now is, that pengine should show âGaming oder Officeâ at the beginning and should wait for the response. But for know it just shows it, after i already made an input. It worked before i used that conditional stuff " (Type = âGamingâ->âŠ; Type=âOfficeâ â âŠ)". Is there anything wrong with my prolog code or what is the problem? Trying to solve this now for like 5 hours and cant fix itâŠ
Hope you guys can help me.