ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 07-14-2008
sophia yao's Avatar
sophia yao sophia yao is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 4
Downloads: 0
Uploads: 0
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
sophia yao is on a distinguished road
Question Double click to execute the onpress function

Hi, all
I wrote several functions within a GUI, the onpress() function worked fairly well with first button, but as for the second button, it works only if I click it twice.
I encountered this problem once with a very simple model and a GUI, the solution I chose then is to open a new model and created the same GUI for a next time. However, perhaps there is something easier to do with this problem.
Regards~
  #2  
Old 07-14-2008
Alex Christensen Alex Christensen is offline
Flexsim Technical Support
 
Join Date: Nov 2007
Location: Provo, UT
Posts: 96
Downloads: 41
Uploads: 8
Thanks: 29
Thanked 141 Times in 56 Posts
Rep Power: 298
Alex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to behold
Default

I share your confusion. This shouldn't happen. Try putting pt("onpress called");pr(); at the beginning of your onpress code and checking the output console. Maybe the code is being called, but the nature of your code switches something each time.
  #3  
Old 07-14-2008
sophia yao's Avatar
sophia yao sophia yao is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 4
Downloads: 0
Uploads: 0
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
sophia yao is on a distinguished road
Question the onpress function works, with several seconds' delay

Thanks, Alex!
Clearly and instantly I find a "onpress called" at the ouput console, however, the result of my onpress fuction appears several seconds later. Perhaps it is because those for loop codings within the onpress function, which controls output of two globaltable.
In addition, my ortho window turns out totally black before compiling the model, is that normal or because of some codings I added?
Eager to know the answer~~
Sophia
  #4  
Old 07-15-2008
Alex Christensen Alex Christensen is offline
Flexsim Technical Support
 
Join Date: Nov 2007
Location: Provo, UT
Posts: 96
Downloads: 41
Uploads: 8
Thanks: 29
Thanked 141 Times in 56 Posts
Rep Power: 298
Alex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to behold
Default

I'm not sure about the compiling, but I think I can help with the tables. Your code probably looks something like this:
Code:
for(int row=1;row<=gettablerows("mytablename");row++){
    for(int col=1;col<=gettablecols("mytablename");col++){
        //you probably don't do something this simple,
        //but it's just an example that doubles each value
        double value=gettablenum("mytablename",row,col);
        double newvalue=2*value;
        settablenum("mytablename",row,col,newvalue);
    }
}
This is slow because every time it references the table, the Flexscript interpreter must parse the string, search through all the tables to find one with the same name, then find the row and column, then do something there. To optimize this code a lot, do something like this:
Code:
treenode tablepointer=reftable("mytablename");
for(int row=1;row<=gettablerows(tablepointer);row++){
    for(int col=1;col<=gettablecols(tablepointer);col++){
        //you probably don't do something this simple,
        //but it's just an example that doubles each value
        double value=gettablenum(tablepointer,row,col);
        double newvalue=2*value;
        settablenum(tablepointer,row,col,newvalue);
    }
}
This only parses the string and searches once. Each time it needs to find the table, it already knows where it is.
The Following 4 Users Say Thank You to Alex Christensen For This Useful Post:
Tom David (07-15-2008)
  #5  
Old 07-15-2008
sophia yao's Avatar
sophia yao sophia yao is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 4
Downloads: 0
Uploads: 0
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
sophia yao is on a distinguished road
Default

Thanks a lot, Alex!
Love the idea!


Thread Thread Starter Forum Replies Last Post
[Suggesiton] UNDO function KelvinHo Gripes and Goodies 10 05-23-2008 01:58 AM
Print function David Chan Gripes and Goodies 0 05-21-2008 09:38 PM
Double load handling ASRS Paul Dowling Q&A 8 05-06-2008 10:19 PM
max() is a deprecated function; use maxof() instead! Lolke Koopmans Gripes and Goodies 0 02-25-2008 02:45 AM
Unable to move the view by left-click dragging? Regan Blackett Tips and Tricks 0 08-03-2007 10:01 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.