Action.WriteINI not working?

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Action.WriteINI not working?

Postby drdna » Sun Feb 15, 2015 8:00 pm

Hello all,

First of all I posted this into another forum area a few days ago but I think it was in the wrong place. So I'm posting it here also.

I cannot seem to include a Action.WriteINI line into a "If, then, else" conditional loop. Here's what I'm trying to do:

I have 6 hotspots. I click a button and I get 6 random buttons in their place. I click it again and I get 6 more random buttons etc. That part works great using a random generator to populate a chal1 variable for button 1, chal2 for button 2, chal3 for button 3, and so on. Now, I need to be able to click on a button, and depending what it is, write to an INI file. The condition I use is this:

Code: Select all
If chal1 = 1 Then
Action.WriteINI "P:\Pushfile.dd",1,1, "Button 1"
ElseIf chal1 = 2 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 2"
ElseIf chal1 = 3 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 3"


This is only for the first 3 but you should get the idea. I use the same type of code for randomizing the buttons and it works fine. I have even verified that the variable is valid by creating a test field on the frame to display it. However, let say that variable "chal1" is 3, and I click the button #3, it does not write anything to the file. I have added some other code and it does execute withing the condition, so the coding is correct. I've also tried JUST the Action.WriteINI "P:\Pushfile.dd",1,1, "Button 3" line and it works perfectly, just NOT with the conditional statement.

I'm at my wits end. Can someone explain why Action.????? works inside a If/then/else statement but WriteINI won't?

Oh, I've even tried a single line condition:

Code: Select all

   If chal1 = 1 then Action.WriteINI "P:\Pushfile.dd",1,1, "Button 1"
   If chal1 = 2 then Action.WriteINI "P:\Pushfile.dd",1,1, "Button 2"
   If chal1 = 3 then Action.WriteINI "P:\Pushfile.dd",1,1, "Button 3"



Nothing works. Why?

Thanks
drdna
Member
 
Posts: 49
Joined: Fri Dec 29, 2006 10:16 pm

Re: Action.WriteINI not working?

Postby reneuend » Mon Feb 16, 2015 1:34 am

I posted a reply to this earlier and its gone. Odd!

I noticed that your path is an absolute path to the "P" drive. I would suggest using the "External" folder on your project and using the "Action.GetPath()" command.
Example:
instead of: Action.WriteINI "P:\Pushfile.dd",1,1, "Button 1"
Use: Action.WriteINI Action.GetPath(2) + "Pushfile.dd", 1,1,"Button 1"

Personally, I didn't care for the INI file. I think it's too cryptic and limiting, so I created my own routines to read and write to files.
If you are curious, you can read about it in the BBB magazine edition 15: http://hickchickgames.com/am_magazine/bbb15.pdf

Maybe I should build a plugin for working with the file system. That way you can check to see if a folder is accessible before writing to it, as an example. I'd feel more inclined to build plugins if we had more users on these forums.

At any rate, let me know how it goes!
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2690
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Action.WriteINI not working?

Postby drdna » Tue Feb 17, 2015 2:08 am

I briefly checked out the article on the alternative but it may not work for my purposes. I'll have to play with it.

You mentioned I should just use the External folder. That won't work for my purposes. Let me try to briefly explain....

I attend an event twice a year for the last 20+ years. We have something called Theme Camps where we create interactive camps for the amusement for others. I create a high-tech Games camp, which I write with AM. No, it's not for profit. It's all just for fun.

This project ( Game ) I wrote several years ago and it's very popular. It's networked between 2 computers ( Thats why I need a static drive letter. It's a shared directory where both computers read and write to the same file ). The game is a challenge game where 2 people send challenges to each other which are timed. They try to get the other person to fail. Great fun!

So, here's the routine:

1. One person sends a challenge. It writes the challenge to a file on the shared drive.
2. The other person reads the file, a timer starts, and they try to complete the challenge in time.
3. If they do, they send a challenge back.
4. Repeat back and forth until someone fails.

It's complex but it's worked perfectly for years. It worked when I pressed a "static" button and wrote the Action.writeINI directly. I had 20 challenges ( Buttons ) per frame. Press a button and it write the file out.

Here is the whole purpose of posting this in this thread: I want to randomize my challenges ( buttons ) and I can do that great. Out of about 50 challenges, when a button is pressed it randomizes them and only displays 6 challenges at a time. You can see how I do this in the code I posted earlier. I use a variable for each challenge ( button ). However, the Action.WriteINI DOES NOT seem to work if called from within a If/Then/Else loop. No matter how I use it, be it an absolute path or the External folder. Is this a bug with the WriteINI object? Do I need to figure another way to do this? I have 3 months to re-write my application but I like to finish things early.

Sorry for the book, but it takes a little to explain. AM Is amazing and I create interesting games with it. But sometimes I run into a glitch like this.

Craig
drdna
Member
 
Posts: 49
Joined: Fri Dec 29, 2006 10:16 pm

Re: Action.WriteINI not working?

Postby reneuend » Tue Feb 17, 2015 4:38 am

That's awesome, craig! Thank you for sharing your story. It's nice to hear some cool ways that AM is being used.
Give me a little time to review this issue. I'll try to come back with something within a week

[UPDATE] I tested the WriteINI in an IF condition to my E drive and it is working fine. I will write up a more complex situation as you have and try it out.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2690
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Action.WriteINI not working?

Postby drdna » Tue Feb 17, 2015 7:06 pm

It worked for you in an if condition? I've even checked my local and network permissions and it still won't work. However, if I use the Action.writeINI line directly, it writes fine to the drive, just not in the IF condition. I don't understand why. You've seen my coding above, am I doing something incorrect?
drdna
Member
 
Posts: 49
Joined: Fri Dec 29, 2006 10:16 pm

Re: Action.WriteINI not working?

Postby reneuend » Tue Feb 17, 2015 10:31 pm

It works in an IF condition. I even used a hard-coded path like you.

I'm not done on this Issue. I just need an opening in my schedule to work on it
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2690
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Action.WriteINI not working?

Postby drdna » Wed Feb 18, 2015 1:47 am

Thanks. I just don't understand why it's not working for me. Truly odd.

Is my code correct? When I use it either way, nothing gets written at all.

Oh well. Thanks for taking the time to check it out. If you don't mind, could you post the exact routine that you used? Maybe I can see something different between the two. Also, I'm using Windows 7. Could that be a problem?
drdna
Member
 
Posts: 49
Joined: Fri Dec 29, 2006 10:16 pm

Re: Action.WriteINI not working?

Postby reneuend » Wed Feb 18, 2015 2:23 am

I'm also using Windows 7.

Here is the routine I used for a simple test:

Code: Select all
if NumAnswered >= TotalQuestions then
  Action.WriteINI "E:\temp\write_ini_test.ini", write_test_section, write_test_key, write_test_value
  MsgBox "Saved!"
else
    MsgBox "You still have " & TotalQuestions - NumAnswered & " questions to answer."
end if


I'll run a test similar to yours. Are you accessing a shared drive?
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2690
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Action.WriteINI not working?

Postby drdna » Thu Feb 19, 2015 1:51 am

Yes, my drive is shared. To be able to have both computers read/write to the directory, I create a shared directory on the local drive and make it drive "P". Then both systems access drive "P" via a network hub on the same workgroup. It works great... until I updated the application to use the If/Then condition.

Edit: This might detail the issue a bit....

Code: Select all
If chal1 = 1 Then
Action.WriteINI "P:\Pushfile.dd",1,1, "Button 1"
ElseIf chal1 = 2 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 2"
ElseIf chal1 = 3 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 3"
ElseIf chal1 = 4 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 4"
ElseIf chal1 = 5 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 5"
ElseIf chal1 = 6 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 6"
ElseIf chal1 = 7 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 7"
ElseIf chal1 = 8 Then
  Action.WriteINI "P:\Pushfile.dd",1,1, "Button 8"
Else
Action.WriteINI "P:\Pushfile.dd",1,1, "Button 16"
End If



I thought maybe the condition required an ELSE command after an ELSEIF. Nope. I keep generating a random "chal1" variable from 1 to 9 with the above example before the code runs. It writes "Button 16" every time. It just will not recognize the IF condition. It will, however, write the line if NOT in a condition as seen above. What am I doing wrong?

EDIT: Ok, I have been playing with this for hours now and it doesn't make sense. However, I've narrowed it down to the IF/THEN/ELSE condition. The write routine works fine so it's not an AM bug as I first thought it was. I've been using the IF condition for years with no problem. And I'm using it in other places it just won't work on this button. But the button routine works because I can place the "Action.writeINI" line at the end and it writes.

So, we can close this thread because it's not a bug. Sorry to take up so much of your time but thank you for trying. I'll find another way to do this, like creating MANY frames with different static buttons that write the line directly, and just randomize the frames instead. Messy but it may work.
Last edited by drdna on Thu Feb 19, 2015 3:19 am, edited 1 time in total.
drdna
Member
 
Posts: 49
Joined: Fri Dec 29, 2006 10:16 pm

Re: Action.WriteINI not working?

Postby reneuend » Thu Feb 19, 2015 3:16 am

I'm going to do a simulation as close as possible to what you did. I'll need a few days as I rarely have time to sit long enough to work on anything during the work week. Expect an post in the next few days.

You could try this instead of the if else construct. It's a lot less code.

Code: Select all
Action.WriteINI "P:\Pushfile.dd",1,1, "Button " & CStr(chal1)
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2690
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Action.WriteINI not working?

Postby drdna » Thu Feb 19, 2015 3:20 am

wow. LOL, we were posting at the same time. lol.

Please read my edit to the last post. Thanks.
drdna
Member
 
Posts: 49
Joined: Fri Dec 29, 2006 10:16 pm

Re: Action.WriteINI not working?

Postby reneuend » Thu Feb 19, 2015 3:27 am

LOL! I hope you see my last post...save you some typing!!! :mrgreen:


UPDATE:
I keep generating a random "chal1" variable from 1 to 9 with the above example before the code runs. It writes "Button 16" every time. It just will not recognize the IF condition. It will, however, write the line if NOT in a condition as seen above. What am I doing wrong?

Code: Select all
Action.WriteINI "P:\Pushfile.dd",1,1, "Button " & CStr(chal1)

Based on this, I think if you replace your entire IF condition with the 1 line I gave you, it will work just fine.

As a test, you might want to be sure that chal1 is an integer and is being set with an integer.
chal1 = CInt( <variable or function call with value that sets your chal1 variable>)
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2690
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Action.WriteINI not working?

Postby drdna » Thu Feb 19, 2015 4:52 am

Yes, chal1 is an integer and your line works. Whatever the variable, it write the correct button to the file.

However, "ButtonXX" is only a placeholder and used for testing. The "actual" buttons will have the actual challenge text on them and writes a more detailed explanation to the file. I have over 100 challenges, which I create a button for each one. So, I don't know how I could use the CStr(chal1).

Anyway, don't lose any more time on this. For some odd reason the hotspot ( Button ) won't run the IF/THEN condition. I don't know why but I'll find another way around it.

I REALLY appreciate the time you put in trying to help but it seems clearly something on my end and not with AM. Thanks again.
drdna
Member
 
Posts: 49
Joined: Fri Dec 29, 2006 10:16 pm

Re: Action.WriteINI not working?

Postby reneuend » Thu Feb 19, 2015 5:07 am

How about trying the Select statement?

Select Case char1
Case 1
'do writeINI
Case 2
.....
End Select
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2690
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 3 guests