News:

Wondering if this will always be free?  See why free is better.

Main Menu

Setting Starting Amount For a Created Field

Started by T D, December 05, 2014, 01:02:25 AM

Previous topic - Next topic

T D

Sorry if the title wording was a bit weird, I wasn't sure of how to phrase it.  Anyways..

I'm working on a simple mod (mostly to mess with some things) and I've come across a problem.  I want to create a field to overwrite a default starting value (in this case, 255 (for custom titles)).  I want to ensure that the field I am making starts with a value other than 0 (i.e. 25) but I have absolutely no idea how to go about this.  Outside of this, everything works fine, I just really don't want the starting value to be 0.

If anyone has any help, please, I would be grateful.

edit: 2.0.9 is the SMF version I am using.

margarett

Hummmm seems this one slipped.

I don't really "visualise" that you're trying to do but, in either case, you can always
if (empty($var))
  $var = xx;
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

instead of posting generic description - can you please indicate SPECIFICALLY what you are trying to do?

What field are you trying to set? With what code?
What are the possible values of the field?
What is the use of the field?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

T D

I create a field in the admin panel where you can set the maximum length for a custom title, but it automatically sets to zero which, in turn, means that once the mod is installed no custom title can be set (as it pulls from this field for the maximum length) which isn't ideal.  Ideally, this value would start at something such as 50.


* in this photo I've already changed the value, it started at zero
Sorry if I am vague, it's been a long few days (I also don't have direct access to the code I added, on a different computer, but it's minor to make this work).

Kindred

Better.

Now... What variable are you using to store the max length?
How are you storing it to the database?  How are you reading it from the database?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

T D

Inside ManageSettings, I added that line you see in the picture;
'',
// Custom Title Limiting
array('int', 'custom_title_len_override_limit'),

and it sets a variable called
custom_title_len_override_limit

Arantor

So you need to populate *that* value in the database at mod install time, yes?

Kindred

ummm.....   and how are your storing that inside the database? (what table? What variable?)

Then, how are you retrieving that information out of the database
(for example when you reload the page where the value is set -- or when the user tries to enter his/her title?)


Also - I would have to look at the code around where you have added those two lines...... but by itself, the code that you posted looks wrong...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

@Kindred: that's a setting handled through the core settings code, which means it would be fine, would be stored inside $modSettings and SMF would do the work automatically.

I'm just trying to establish the way he wants to play this; there's two routes, either he can test the relevant $modSettings value for existence (using isset rather than empty), and using it if set and ignoring it if not; or he can test for isset during installation by doing much the same with an install script and then calling updateSettings() to set a value if one does not exist.

Kindred

I bow to your superior knowledge of the code.:)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

T D

Quote from: Arantor on December 19, 2014, 10:18:13 PM
@Kindred: that's a setting handled through the core settings code, which means it would be fine, would be stored inside $modSettings and SMF would do the work automatically.

I'm just trying to establish the way he wants to play this; there's two routes, either he can test the relevant $modSettings value for existence (using isset rather than empty), and using it if set and ignoring it if not; or he can test for isset during installation by doing much the same with an install script and then calling updateSettings() to set a value if one does not exist.
Thanks, this should help!

@Kindred and margarett: thanks as well!

Advertisement: