Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Python bridge - wrong output sample #477461
06/30/19 09:35
06/30/19 09:35
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline OP
Senior Member
Grat  Offline OP
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
Hi,

I trying the python sample:
Code

   if(!pyStart(0,1)) {
    printf("Error - Python won't start!");
    return;
  }


  var Vec[5] = { 0,1,2,3,4 };
  pySet("PyVec",Vec,5);
  pyX("for i in range(5): PyVec[i] *= 10\n");
  pyVec("PyVec",Vec,5);

  int i;
  printf("\nReturned: ");
  for(i=0; i<5; i++) printf("%.0f ",Vec[i]);

// test a function
  
  pyX("def PySum(V):\n Sum = 0.0\n for X in V:\n Sum += X\n return Sum\n\n");
  pyX("Result = PySum(PyVec)");
  printf("\nSum: %.0f",pyVar("Result"));


output the Sum is -1, but correct is 100

Re: Python bridge - wrong output sample [Re: Grat] #477463
06/30/19 10:29
06/30/19 10:29
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Maybe not var but int?

Re: Python bridge - wrong output sample [Re: Grat] #477465
06/30/19 15:29
06/30/19 15:29
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline OP
Senior Member
Grat  Offline OP
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
no, becouse is:
Code
...
Sum = 0.0
....


this working (return 100):
Code
pyX("Sum=0");
pyX("for X in PyVec: Sum += X");


this code also work:
Code
  pyX("def PySum(V):\n\tSum=0\n\tfor X in V:\n\t\tSum =Sum+ X\n\treturn( Sum)\n\n");
  pyX("Sum=PySum(PyVec)");
  printf("\nSum: %f",pyVar("Sum"));


so, is a better use \t not space,

Last edited by Grat; 06/30/19 15:44.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1